簡體   English   中英

在Android中設置操作欄的背景顏色

[英]Set Background color of Action Bar in Android

您好,我是Android的菜鳥。

我正在使用appcompat支持庫來使我的應用程序向后兼容。 在這里,操作欄顏色默認為Light ,我想將背景色更改為自定義顏色。

任何想法如何做到這一點?

styles.xml

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

在此處輸入圖片說明

這解決了我的問題。 謝謝@Zohra

ActionBar mActionBar = getActionBar();
mActionBar.setBackgroundDrawable(new ColorDrawable("COLOR"));

您可以嘗試使用官方文檔中的方法。 我認為這有一個明確的例子。

你的風格可能看起來像這樣

參考: -https : //developer.android.com/training/basics/actionbar/styling.html

  <style name="CustomActionBarTheme"
       parent="@style/Theme.AppCompat.Light">

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
  </style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_background</item>
</style>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM