设置状态栏颜色以配合MaterialToolbar?

huangapple go评论69阅读模式
英文:

Set status bar color relative to MaterialToolbar?

问题

以下是您要翻译的内容:

我想将我的状态栏颜色设置为与我在活动中拥有的给定MaterialToolbar相同的颜色。

我正在使用包含Configuration.UI_MODE_NIGHT_YESConfiguration.UI_MODE_NIGHT_NO的switch case来设置应用程序的白天模式或夜间模式,并且我希望我的状态栏能够匹配。

在白天模式下,我使用AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);将我的活动从夜间模式中移出,而使用AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);来设置夜间模式。这基本上是一个开关。

我的MaterialToolbar在默认情况下在ColorPrimary和其夜间模式等效颜色之间进行切换。我的问题是,我如何使我的状态栏以相同的颜色更改,最好是通过样式。因为目前我将其设置为:<item name="android:statusBarColor">?attr/isLightTheme</item>

如果无法通过样式实现,我如何以编程方式设置它?

谢谢。

英文:

I'd like to set my status bar color to be the same as a given MaterialToolbar I have in my activity.

I am using switch cases consisting of Configuration.UI_MODE_NIGHT_YES & Configuration.UI_MODE_NIGHT_NO: to set the application to Day or NightMode and I would like to have my statusbar match.

on YES I utilize AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); to take my activity out of NightMode & AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); to set NightMode. It is basically a switch.

My MaterialToolbar alternates between the ColorPrimary I have it set on default and it's NightMode equivalent. My question is, how can I get my statusbar to change to the same colors, preferably as a style. As I have it set to: &lt;item name=&quot;android:statusBarColor&quot;&gt;?attr/isLightTheme&lt;/item&gt; for the time being.

If it is not possible through styles, how would I set it programatically?

Thanks.

答案1

得分: 0

我相信我已经找到了一个解决方案,只需在新的资源文件夹中添加一个“-night”限定符。在那里替换不同模式之间所需的信息。

例如,在我的情况下,StatusbarColor可以在白天和夜晚的样式值之间更改。

英文:

I believe I have found a solution, simply. add a -night qualifier to a new resource folder. Replace required information between the modes there.

For example in my case, StatusbarColor can be changed between day and night style values.

huangapple
  • 本文由 发表于 2020年10月17日 06:26:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64397174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定