2016-03-14 78 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>