[英]Setting background color of android actionbar
我正在使用兼容性庫v7。
我只是想將操作欄的顏色(適用於Android 2.1及更高版本-盡管我運行Android 4.4.2)設置為純色。
但是顏色不會改變。 它保持不變。
我也嘗試過用顏色創建一個可繪制的實體,但是它也不會改變。
最后,我測試了是否可以更改布局的背景,並且可以-它一定是關於我沒有得到的操作欄背景的內容。
這是代碼:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">#0000ff</item>
</style>
</resources>
這似乎為我工作。 嘗試使用資源而不是原始值。
<style name="app_theme" parent="@android:style/Theme.Holo">
<item name="android:actionBarStyle">@style/app_action_bar</item>
</style>
<style name="app_action_bar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@color/google_lightest_gray</item>
<item name="android:icon">@android:color/transparent</item>
<item name="android:windowActionBarOverlay">false</item>
</style>
使用getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#808080")));
在Activity extends SherlockActivity
或根據需要選擇顏色:)
您可以使用:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.colorname));
使用以下代碼getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg_color.xml));
actionbar_bg_color.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/actionbar_bg"/> <!-- set desired #0000ff color in color.xml
you can use here solid color as well as gradient -->
</shape>
希望這對你有幫助
我通過以下方法解決了它:
我不知道為什么不能在themes.xml中得到想要的結果。
如果有人有答案,我將不勝感激
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.