簡體   English   中英

在Android中更改操作欄顏色

[英]Change an action bar color in Android

這個問題已經問到堆棧溢出但是對我不起作用。

我想改變我的動作欄顏色,就像facebook app一樣,頂部動作是藍色,其余的東西都是白色背景顏色。

我嘗試在堆棧溢出中使用帖子但是,它將我的完整活動顏色更改為白色而不僅僅是操作欄。

這是我的style.xml和

<style name="CustomActivityTheme" parent="@android:style/Theme.Holo">
    <item name="android:actionBarTabStyle">@color/blue_base</item>
    <!-- other activity and action bar styles here -->
</style>

的manifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomActivityTheme">

謝謝。

你不能直接使用顏色,你必須使用drawable:

action_bar_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/blue_base"/>
</shape>

那應該工作:

<item name="android:actionBarTabStyle">@drawable/action_bar_bg</item>

現在我意識到你做錯了什么。 你不能將顏色傳遞給actionBarTabStyle ,你必須傳遞樣式。 相反,您可以定義您的style並將其傳遞給它,就像這樣,

<style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@drawable/ab_background</item>
</style>

這個例子來自Android Developers頁面,如果你看看那里他們解釋得很好。

Android開發者博客上還有另一篇好文章

暫無
暫無

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

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