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

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

我想在我的工具栏(应用 bar/title 栏)中添加颜色渐变。

我已经在名为 "side_nav_bar.xml" 的可绘制文件夹中创建了一个 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" />

我在互联网上找到了一些关于创建新的自定义工具栏然后将其设置为背景图片等的建议。但是我没有足够的相关信息。

我们将不胜感激任何帮助。 谢谢

试试这个

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