Reputation: 514
What i want? I want to make the ActionBar color customizable, users can select a color from a list of colors and the ActionBar color will be changed to their selected color.
What i have done? I have a class named SettingsActivity in which i take color choice from user. The color they select is stored in SharedPreferences. The color user selected is getting stored in SharedPreferences and then i restart the application through an intent the color change take place. Everything is working as it should.
But there is a problem whenever i start the application for a small interval of time the app shows the default color that i have at styles.xml in values v-14 folder and then the color changes to user selected color. How can i eliminate this bug?
I'm also attaching the code of styles.xml. If any other detail or code is required then do let me know i will provide that as well and I am using 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>
Upvotes: 1
Views: 206
Reputation: 46
Use this for change action bar color:_
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
OR use this one
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#ffFEBB31"));
actionBar.setBackgroundDrawable(colorDrawable);
Thanks
Upvotes: 1