gpt4 book ai didi

Android 自定义 ActionBar 颜色?

转载 作者:行者123 更新时间:2023-11-30 02:34:27 25 4
gpt4 key购买 nike

我想要什么?我想让 ActionBar 颜色可自定义,用户可以从颜色列表中选择一种颜色,ActionBar 颜色将更改为他们选择的颜色。

我做了什么?我有一个名为 SettingsActivity 的类,我在其中从用户那里选择颜色。他们选择的颜色存储在 SharedPreferences 中。用户选择的颜色存储在 SharedPreferences 中,然后我通过更改颜色的 Intent 重新启动应用程序。一切正常。

但是每当我启动应用程序一小段时间时就会​​出现问题,应用程序会显示我在 styles.xml 中 values v-14 文件夹中的默认颜色,然后颜色会更改为用户选择的颜色。我怎样才能消除这个错误?

我还附上了 styles.xml 的代码。如果需要任何其他详细信息或代码,请告诉我我也会提供,我正在使用 Navigation Drawer Fragments。

<resources>

<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
API 14 theme customizations can go here.
</style>
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#f39c12</item>
</style>
</resources>

最佳答案

使用它来改变操作栏颜色:_

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));

或者使用这个

    ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#ffFEBB31"));
actionBar.setBackgroundDrawable(colorDrawable);

谢谢

关于Android 自定义 ActionBar 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26800426/

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