[英]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.