我定义了一个渐变可绘制:
<?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)
关于android - 带有渐变背景的工具栏设置标题背景透明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28817109/