简体   繁体   English

如何向工具栏添加颜色渐变(Android)

[英]How can I add a color gradient to the toolbar (Android)

I want to add a color gradient to my toolbar (app bar/title bar). 我想向工具栏(应用程序栏/标题栏)添加颜色渐变。

I've created an xml gradient file to the drawable folder called "side_nav_bar.xml". 我已经将XML渐变文件创建到名为“ side_nav_bar.xml”的可绘制文件夹中。

side_nav_bar.xml side_nav_bar.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:angle="135"
    android:endColor="#7524f6"
    android:startColor="#2691f6"
    android:type="linear" />

I found some suggestions on the internet to create a new custom toolbar then set this as the background image etc. But I don't have enough info about this. 我在互联网上找到了一些建议来创建一个新的自定义工具栏,然后将其设置为背景图像等。但是我没有足够的信息。

Any help will be highly appreciated. 任何帮助将不胜感激。 Thanks. 谢谢。

Try this 尝试这个

ActionBar actionbar = getSupportActionBar();
actionbar.setBackgroundDrawable(getResources().getDrawable(R.drawable.side_bar_nav));

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM