2015-02-26 43 views
2

在繼續this question的其餘部分兩者的背景顏色,我想更改同時動作條的顏色(上部窗格),以一種顏色和屏幕的其餘部分與不同的顏色。
我該怎麼做?
當我嘗試這樣做 -更改動作條並且活動

<style name="MyTheme" parent="@style/Theme.AppCompat.Light"> 
     <item name="android:actionBarStyle">@style/MyActionBar</item>   
     <item name="android:background">#ffffd982</item> 
</style> 

它似乎像「機器人:背景」的定義也覆蓋了actionbarstyle定義

回答

2

事實上,background屬性是已知的取代的actionBarStyle屬性。但是,更改整個Activity的顏色需要通過Activity的XML佈局,使用父ViewGroupandroid:background屬性完成。 ActionBar款式不會幫助你。

在你Activity的根ViewGroup,設置background屬性爲:

<LinearLayout 
    android:id="@+id/outermost_viewgroup" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background = "#00FF00" 
    .... 
    .... 

編輯:

我剛剛意識到有一個用於這種方式:

<item name="android:windowBackground">@color/background</item> 

將上面的標籤添加到您的ActionBar樣式定義,並在colors.xml文件background

<resources> 
    <color name="background">#00FF00 </color> 
</resources> 

那裏,這樣做!

+0

您好,我想設定背景爲我的應用程序的所有活動,而不是一個單一的活動 – GyRo

+0

我完全忘了,有一個方式做你想要的...請參閱編輯答案! –

+0

@GyRo:你試過編輯了嗎? –

0

要改變動作條的風格在你style.xml文件中定義的風格像波紋管

<style name="AppBaseTheme" parent="android:Theme.Light"> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
</style> 

<style name="MyActionBar" parent="@android:style/Widget.ActionBar"> 
    <item name="android:background"><YourColor></item> 
    <item name="android:titleTextStyle"><Your String Color></item> 
</style> 

在你menifest.xml文件中使用的內部應用程序標記你的風格像波紋管

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

併爲您的活動設置背景顏色只需設置android:background屬性在你喜歡

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ff2323" 
tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textView2" 
    android:layout_below="@+id/textView2" 
    android:layout_marginTop="121dp" 
    android:text="Medium Text" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

我認爲這是對你工作的每個活動...!