如何在android的工具栏中应用渐变?
说明: 我想在工具栏上应用渐变。我已经做到了。我在style.xml中的应用程序主题上应用了这个渐变 这是我的style.xml如何在android的工具栏中应用渐变?,android,Android,说明: 我想在工具栏上应用渐变。我已经做到了。我在style.xml中的应用程序主题上应用了这个渐变 这是我的style.xml <resources> <style name="MyMaterialTheme" parent="MyMaterialTheme.Base"> </style> <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.Da
<resources>
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@drawable/toolbar_gradient</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MyMaterialTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="MyMaterialTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="MyTabLayoutTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse">
<item name="android:textSize">16sp</item>
<item name="android:textAllCaps">true</item>
</style>
</resources>
colorPrimary
应该指定一种颜色(实际上只是一个整数),并且您使用的是ShapeDrawable
如果您想在工具栏背景中使用gradient.xml
,只需在工具栏背景中使用它即可
将颜色更改为实际颜色
<item name="colorPrimary">@color/colorPrimary</item>
@color/colorPrimary
在工具栏上,将可绘制图形作为背景:
<android.support.v7.widget.Toolbar
... parameters...
android:background="@drawable/gradient"
/>
colorPrimary
应该被赋予一种颜色(实际上只是一个整数),并且您正在使用一个可变形的
如果您想在工具栏背景中使用gradient.xml
,只需在工具栏背景中使用它即可
将颜色更改为实际颜色
<item name="colorPrimary">@color/colorPrimary</item>
@color/colorPrimary
在工具栏上,将可绘制图形作为背景:
<android.support.v7.widget.Toolbar
... parameters...
android:background="@drawable/gradient"
/>
您的形状文件名是什么?它是gradient.xml
或toolbar\u gradient.xml
请指定.toolbar\u gradient.xml1)它被称为colorPrimary
,它应该告诉您在其中放置颜色资源,而不是可绘制的。2) 在主题的前两行禁用了默认的操作栏。3) 请告诉我如何应用适用于每个版本的toolbar_gradient.xml?在上面的v21中,stylecolorPrimary
表示您只需要定义颜色名称。您的形状文件名是什么gradient.xml
或toolbar_gradient.xml
specify.toolbar_gradient.xml1)它被称为colorPrimary
,它应该告诉您在其中放置颜色资源,而不是可绘制的。2) 在主题的前两行禁用了默认的操作栏。3) 在不使用android:前缀的情况下使用此选项。因此,请告诉我如何应用适用于每个版本的toolbar_gradient.xml?在上面的v21中,stylecolorPrimary
表示您只需要定义其颜色名称。
<item name="colorPrimary">@color/colorPrimary</item>
<android.support.v7.widget.Toolbar
... parameters...
android:background="@drawable/gradient"
/>