Reputation: 55
How would I go about having different toolbar/navigation bar colours for different activities. I've tried creating two custom themes but I just can't get them to inherit these different themes.
Acitivity 1 - Currently blue theme
Activity 2 - Want this to have a grey theme.
<?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>
Upvotes: 2
Views: 1970
Reputation: 6663
Did you tried this in your onCreate
.
setTheme(R.style.YourAppTheme);
You can create many themes in your res/values/styles.xml
One example :
<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>
Upvotes: 0
Reputation: 74
Change the theme in the manifest of the desire activity, so it would look something like this:
<activity
android:name=".activities.YourActivity"
android:theme="@style/YourGrayTheme" />
Upvotes: 1
Reputation: 2087
You can create a your own theme
that just includes a color. Then you will be able to set all of the properties you need to that theme, thus changing the color.
Upvotes: 0
Reputation: 961
In the AndroidManifest
where you add the activity, you can also specify the theme of the activity. If you already have the custom themes, it's as simple as adding
android:theme="@style/MyBlueTheme"
and android:theme="@style/MyGreyTheme"
Upvotes: 0