Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change ColorPrimaryDark for just one activity?

Tags:

android

kotlin

I would like to change the color of ColorPrimaryDark for just one activity. How can I do this?

I think go to the styles.xml and change this:

<item name="colorPrimaryDark">@color/blue</item>

But the problem is if I do this I change the color of all my activities and I just need to change the color of one activity.

Thank you for your help!

To be specific, this color is the color of the bar at the top of the app I mean above of ActionBar. I use Kotlin to do this.

like image 405
Norman Wildermuth Avatar asked Dec 23 '22 15:12

Norman Wildermuth


1 Answers

Create a theme specifically for that Activity.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimaryDark">@color/gray</item>
    <!-- Your application theme -->
</style>

<style name="BlueActivityTheme" parent="AppTheme">
    <item name="colorPrimaryDark">@color/blue</item>
</style>

Then in your manifest, apply the theme to only that Activity:

<activity android:name="com.example.app.BlueActivity"
    android:theme="@style/BlueActivityTheme"/>
like image 83
Bryan Avatar answered Dec 28 '22 06:12

Bryan