【问题标题】:How can I make my toolbar a gradient in colors.xml?如何使我的工具栏在colors.xml 中渐变?
【发布时间】:2016-06-13 10:33:07
【问题描述】:

如何在colors.xml 中使我的工具栏在#11FFBD#AAFFA9 之间渐变?我的纯蓝色标题代码是:

<color name="primary">#00BCD4</color>
<color name="primary_dark">#00838F</color>
<color name="primary_pressed">#0097A7</color>

【问题讨论】:

    标签: android android-studio ui-design


    【解决方案1】:

    在您的可绘制文件夹中创建:gradient_toolbar.xml 像这样

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="rectangle">
    
    <gradient
    android:type="linear"
    android:startColor="#11FFBD"
    android:endColor="#AAFFA9"
    android:angle="270"/>
    </shape>
    

    并在您的工具栏声明中添加以下内容:

    <android.support.v7.widget.Toolbar
    
    android:id="@id/toolbar"
    android:background="@drawable/gradient_toolbar"
    
    <!--your other attributes-->
    
    />
    

    【讨论】:

    • 当我尝试这个时,我收到以下错误:错误:任务':app:mergeDebugResources'的执行失败。 > C:\Users\Craig\Desktop\PapuhWalls-master\PapuhWalls-master\app\src\main\res\values\colors.xml:9:15: 错误:属性“android:id”的前缀“android”与元素类型“android.support.v7.widget.Toolbar”关联的未绑定。
    • 您将工具栏放在单独的 xml 文件中?
    猜你喜欢
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-03
    相关资源
    最近更新 更多