简体   繁体   English

未折叠时Android折叠工具栏的背景颜色

[英]Android Collapsing toolbar background color when not collapsed

In my application I have collapsing toolbar with image header. 在我的应用程序中,我有带有图像标题的折叠工具栏。 When the toolbar is in not-collapsed state ( when header is visible), the icons on toolbar are not clearly visible due to white color of header image. 当工具栏处于未折叠状态时(当标题可见时),由于标题图像为白色,因此无法清晰看到工具栏上的图标。 So how can I change the toolbar color in not-collapsed state to semi transparent black. 因此,如何将未折叠状态下的工具栏颜色更改为半透明黑色。

I know that for changing background color in collapsed state we use :- ContentScrim. 我知道,要在折叠状态下更改背景颜色,我们使用:-ContentScrim。

Thanks 谢谢

Create scrim.xml by yourself and put it into your Toolbar between background ImageView and title TextView using FrameLayout. 自己创建scrim.xml,并使用FrameLayout将其放入背景ImageView和标题TextView之间的工具栏中。

<android.support.v7.widget.Toolbar
    android:id="@+id/tool_bar"
    android:theme="@style/ToolBarStyle"
    android:layout_width="match_parent"
    android:layout_height="80dp"
     >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/background_img"
            android:scaleType="center"
            />
        <View android:background="@drawable/scrim"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Your Title"
            android:textSize="@dimen/abc_text_size_title_material"
            android:textAlignment="center"
            />
    </FrameLayout>
</android.support.v7.widget.Toolbar>

And create res/drawable/scrim.xml (Please adjust alpha darkness to your need). 并创建res / drawable / scrim.xml(请根据需要调整Alpha暗度)。

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <gradient
        android:angle="-90"
        android:startColor="#00000000"
        android:centerColor="#00000000"
        android:endColor="#4d000000"
        android:type="linear" />
</shape>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 折叠工具栏折叠时如何更改折叠工具栏的颜色? - How do you change the color of collapsing toolbar when it's collapsed? 折叠工具栏折叠时隐藏浮动按钮 - Hide floating button when collapsing toolbar is collapsed 默认情况下折叠折叠工具栏 - Collapsing toolbar is collapsed by default Android折叠工具栏在折叠时未隐藏其他元素 - Android Collapsing Toolbar was not hiding other element while collapsed 如何在不滚动android的情况下将折叠的工具栏显示为折叠 - How to show collapsing toolbar as collapsed without scrolling android Android折叠工具栏溢出菜单有背景 - Android Collapsed Toolbar overflow menu has background android - 带有 tablayout 设置背景的折叠工具栏 - android - collapsing toolbar with tablayout set background Android Material Design-CollapsingToolbarLayout折叠后如何更改工具栏的背景颜色 - Android Material Design - How to change background color of Toolbar after CollapsingToolbarLayout is collapsed 如何在Android中更改折叠工具栏的文本颜色和折叠工具栏的后退按钮颜色 - How to change the Text color of collapsing toolbar and the back button color of collapsing toolbar in android 如何在折叠的工具栏中实现透明的标签布局背景? 并为折叠的工具栏android提供背景或渐变效果? - How to achieve transparent background for tab layout in collapsing toolbar ? and give a background or gradient effect to collapsing toolbar android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM