如何只为一项活动更改ColorPrimaryDark? [英] How can I change ColorPrimaryDark for just one activity?

查看:161
本文介绍了如何只为一项活动更改ColorPrimaryDark?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想更改一项活动的ColorPrimaryDark颜色.我该怎么办?

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

我认为请转到styles.xml并进行以下更改:

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.

谢谢您的帮助!

具体来说,此颜色是应用顶部的栏的颜色,我指的是ActionBar上方的颜色.我使用Kotlin来做到这一点.

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.

推荐答案

创建一个主题专门用于该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>

然后在清单中将主题仅应用于Activity:

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

<activity android:name="com.example.app.BlueActivity"
    android:theme="@style/BlueActivityTheme"/>

这篇关于如何只为一项活动更改ColorPrimaryDark?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆