gpt4 book ai didi

java - 我无法更改 ActionBar 颜色

转载 作者:行者123 更新时间:2023-11-30 00:23:03 24 4
gpt4 key购买 nike

我想使用我的自定义主题来更改 ActionBar 的颜色,但我不能。
这是我的 styles.xml 文件:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="NewTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/CustomActionBar</item>
</style>

<style name="CustomActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/pink</item>
</style>

这是我的 AndroidManifest.xml 文件:

<?xml version="1.0" encoding="utf-8"?>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/NewTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

看看这个:

android:theme="@style/AppTheme.NoActionBar"

如果我将这个主题更改为 CustomActionBar 或 NewTheme,一切看起来都很正常,但是当我启动我的虚拟设备时,我会看到:

enter image description here

我研究了很多资源,但找不到答案。
我怎样才能解决这个问题?请帮助我!

最佳答案

您可以通过编程方式执行此操作

ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
Drawable drawable = getResources().getDrawable(R.drawable.yourColor);
actionBar.setBackgroundDrawable(drawable);
}

关于java - 我无法更改 ActionBar 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45918724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com