如何更改工具栏颜色 [英] How to change toolbar color

查看:75
本文介绍了如何更改工具栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找如何自定义工具栏,例如如何添加背景颜色,但我不明白它是如何工作的.

I've been searching how to customize the toolbar, for example how to add background color, but I don't understand how it works.

我一直在尝试为我的工具栏添加自定义样式,但没有任何结果...

I've been trying to add a custom style for my toolbar but any result ...

清单

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Design">

style.xml 文件

The style.xml file

<resources>

    <style name="Theme.Design" parent="Base.Theme.Design">
    </style>

    <style name="Base.Theme.Design" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/red</item>
        <item name="colorPrimaryDark">@color/red</item>
        <item name="colorAccent">@color/red</item>
        <item name="android:textColorPrimary">@color/white</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="windowActionBarOverlay">true</item>
    </style>    
    ...

和布局中的工具栏

<android.support.v7.widget.Toolbar
            android:id="@+id/home_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>

推荐答案

谢谢,但任何解决方案都有效.

Thanks, but any solution works.

 <android.support.v7.widget.Toolbar
            android:id="@+id/home_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"/>

toolbar.setBackgroundColor(Color.parseColor("#80000000"));

可能是因为我的工具栏在 android.support.design.widget.CoordinatorLayout(放置一个 android.support.design.widget.FloatingActionButton)?

May be because my toolbar is in android.support.design.widget.CoordinatorLayout (to put a android.support.design.widget.FloatingActionButton) ?

这篇关于如何更改工具栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆