Different toolbar colors for different activities android

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>

Answers


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" />

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"


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.


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>

Need Your Help

How do you do inheritance in a non-OO language?

c++ c oop inheritance history

I read that early C++ "compilers" actually translated the C++ code to C and used a C compiler on the backend, and that made me wonder. I've got enough technical knowledge to wrap my head around mo...

How to change color of intersected parts of CAShapeLayer in Objective-C?

iphone objective-c ios graphics cashapelayer

I am trying to draw CGPaths using CAShapeLayer. I want to change the color of the parts where lines are intersected.