[英]Toolbar with Gradient Background set title background transparent
我定义了一个渐变可绘制:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:endColor="#2F3F59"
android:startColor="#4078A7"
android:type="linear"
android:angle="90" />
</shape>
我将它设置在我的工具栏上:
<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@color/textcolorsecundary</item>
<item name="actionMenuTextColor">@color/textcolorsecundary</item>
<item name="android:textColorSecondary">@color/textcolorsecundary</item>
<item name="android:background">@drawable/custom_background_blue</item>
</style>
这是有效的! 但是:
这就是标题发生的情况。 它得到相同的梯度。 这看起来真的很丑,所以我必须改变它。 如何将该信息文本的背景设置为透明?
您还可以通过将工具栏的背景设置为可绘制对象来解决此问题。
mToolbar().setDrawable(R.drawable.your_gradient)
在您的颜色 xml 文件中使用此颜色,然后将此颜色赋予您的开始颜色和结束颜色
解决方法是禁用工具栏的标题:
this.getSupportActionBar().setDisplayShowTitleEnabled(false);
并添加自定义TextView
:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:elevation="2dp"
android:focusable="false"
android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:theme="@style/AppTheme.Toolbar" >
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="@null"
android:text="Toolbar Title"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
在样式部分将背景颜色更改为透明应该可以解决问题
<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">#00000000</item>
</style>
如何使标题背景在 android 应用程序上透明的问题在上面的解决方案上有类似的问题。 安卓应用程序适用于瑞萨 RX130 和德州仪器 CC2650 BLE 解决方案。 波纹管是修复后的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.