2016-03-14 58 views
1

我該如何着手爲不同活動設置不同的工具欄/導航欄顏色。我試過創建兩個自定義主題,但我無法讓他們繼承這些不同的主題。針對不同活動的不同工具欄顏色android

Acitivity 1 - 目前藍色主題

Activity 2 - 希望這有一個灰色的主題。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.andrewfinlay.vectorcalculator"> 

    <application 
     android:allowBackup="true" 
     android:fullBackupContent="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" 
      android:launchMode="singleTask" 
      android:theme="@style/AppTheme.NoActionBar"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".SettingsActivity" 
      android:label="@string/title_activity_settings" 
      android:launchMode="singleTask" 
      android:theme="@style/AppTheme.NoActionBar"></activity> 
     <activity 
      android:name=".AboutActivity" 
      android:label="@string/title_activity_about" 
      android:launchMode="singleTask" 
      android:theme="@style/AppTheme.NoActionBar"></activity> 
     <activity 
      android:name=".ThemeActivity" 
      android:label="@string/title_activity_theme" 
      android:theme="@style/AppTheme.NoActionBar"></activity> 
    </application> 

</manifest> 

回答

1

變化的慾望活動清單中的主題,所以它看起來是這樣的:

<activity 
     android:name=".activities.YourActivity" 
     android:theme="@style/YourGrayTheme" /> 
0

在您添加活動的AndroidManifest中,還可以指定活動的主題。如果您已經有自定義主題,它是那樣簡單添加

android:theme="@style/MyBlueTheme"android:theme="@style/MyGreyTheme"

+0

在'AndroidManifest'它說'機器人:主題= 「@風格/ AppTheme.NoActionBar」>'但仍然是藍色的。 – Sectah

+0

因此AppTheme.NoActionBar可能沒有爲操作欄設置值,如其標題所示。在這種情況下,它可能會降低你的應用程序主題。你能發佈你的AndroidManifest的內容嗎? – Chris

+0

更新了帖子 – Sectah

0

您可以創建一個自己的theme,僅僅包括顏色。然後你就可以設置你需要的所有屬性,從而改變顏色。

0

你有沒有在你的onCreate嘗試這個。

setTheme(R.style.YourAppTheme); 

您可以創建多個主題的res/values/styles.xml

一個例子:

<style name="YourAppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="android:windowTranslucentStatus">true</item> 
    <item name="android:windowTranslucentNavigation">true</item> 
    <item name="colorPrimary">@color/ColorPrimary</item> 
    <item name="colorPrimaryDark">@color/ColorPrimaryDark</item> 
    <item name="android:colorAccent">@color/ColorPrimary</item> 
    <item name="android:statusBarColor">@color/ColorPrimary</item> 
    <!-- you can customize your theme here. --> 
</style> 
相關問題