How to set background image for IcsSpinner and its drop down view resource using action bar sherlock in android - actionbarsherlock

How to add style for IcsSpinner using action bar sherlock in android. If anyone know how to set different background image for IcsSpinner and Drop down view resource

<style name="AppTheme" parent="#style/Theme.Sherlock">
<item name="android:actionDropDownStyle">#style/DropDownNav</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView</item>
</style>
<style name="DropDownListView" parent="#android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background</item>
</style>
<style name="DropDownNav" parent="#android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/spinner_background_ab</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
<item name="android:dropDownSelector">#drawable/selectable_background</item>
</style>
Check out ActionBar Style Generator

Related

App Bar not following Headline 6 text appearance in dark theme (Material Design Components)

Project with MDC doesn't follow the fontFamily I set in Headline 6 in my theme when on dark theme.
I used metropolis_500 as my fontFamily in my Headline 6 style. It shows up normally on Light Theme but not on Dark Theme.
implementation 'com.google.android.material:material:1.1.0'
<!--Base Theme-->
<style name="Base.Theme.MyApp" parent="Base.Theme.MaterialThemeBuilder">
...
<item name="textAppearanceHeadline6">#style/TextAppearance.MyTheme.Headline6</item>
<item name="toolbarStyle">#style/Widget.MyTheme.Toolbar.AppBar</item>
...
</style>
<!--AppBar Style-->
<style name="Widget.MyTheme.Toolbar.AppBar" parent="Widget.MaterialComponents.Toolbar.Surface">
<item name="android:background">?attr/colorAppBar</item>
<item name="titleTextColor">?colorOnAppBar</item>
</style>
<!--Headline 6-->
<style name="TextAppearance.MyTheme.Headline6" parent="TextAppearance.MaterialComponents.Headline6">
<item name="fontFamily">#font/metropolis_500</item>
</style>
I tried explicitly specifying the use of Headline 6 in my AppBar Style and did not work.
<!--AppBar Style-->
<style name="Widget.MyTheme.Toolbar.AppBar" parent="Widget.MaterialComponents.Toolbar.Surface">
<item name="android:background">?attr/colorAppBar</item>
<item name="titleTextColor">?colorOnAppBar</item>
<item name="titleTextAppearance">#style/TextAppearance.MyTheme.Headline6</item>
</style>
I also tried explicitly specifying the toolbarStyle on Dark Theme Style.
<style name="Theme.MyApp" parent="Base.Theme.MyApp">
...
<item name="toolbarStyle">#style/Widget.MyTheme.Toolbar.AppBar</item>
</style>
I also tried reverting to the default Material Components toolbarStyle.
<item name="toolbarStyle">#style/Widget.MaterialComponents.Toolbar.Surface</item>
Nothing worked. Light theme is alright, but dark theme isn't. The metropolis font shows up properly on other parts in dark theme like in TextViews that use the Headline 6 style.

Changing actionbar color not working

I'm trying to change my action bar color to royal blue but it stays black despite everything I try. I've set the color code in my color.xml file and the theme is set to AppTheme in AndroidManifest.xml. I don't know what else could cause it to not work. Here is my styles.xml:
<!-- Base application theme. -->
<style name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar">
<item name="android:background">#color/royal_blue</item>
</style>
It is recommended to use "colorPrimary" for configuring action bar color. You can use following files for styles configuration.You are recomended to use Toolbar to act as ActionBar
values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:textColorSecondary">#color/textColorSecondary</item>
</style>
<!-- Application theme to be used -->
<style name="AppTheme" parent="AppTheme.Base"></style>
</resources>
values-v22/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">#color/primaryColor</item>
<item name="android:colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:colorAccent">#color/accentColor</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:textColorSecondary">#color/textColorSecondary</item>
</style>
</resources>
Please note to create another folder in in res folder named values-v22.This will be used by Lollipop devices.And values/styles.xml will be used by pre-lollipop devices.

Android action bar not reflecting color change

I've read numerous answers regarding changing the color of the action bar, but I can't seem to get it to work. Here's what I have:
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">#color/actionBarBackground
</item>
</style>
</resources>
I've also tried
<item name="android:Background">#F33</item>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
You are changing the android:windowBackground not the background of your ActionBar.
In any case, starting with the AppCompat v21+, you can use a new way to customize your ActionBar.
All of your Activities must extend from AppCompatActivity
All of your themes (that want an ActionBar/Toolbar) must inherit from Theme.AppCompat.
Just use a theme like this:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">#color/my_awesome_red</item>
<item name="colorPrimaryDark">#color/my_awesome_darker_red</item>
<!-- The rest of your attributes -->
</style>
The current version of AppCompat is 23. It requires API23 to compile the project.
The following seems to have done the trick. I found it here Change Background color of the action bar using AppCompat
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:background">#color/actionBarBackground</item>
<item name="background">#color/actionBarBackground</item>
</style>
However, now my android:label in my manifest file is being covered by the background color, so I added
<item name="android:displayOptions">showTitle</item>
<item name="displayOptions">showTitle</item>

AppCompat ActionBar Background Color

I have this style.xml inside my Android app:
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<style name="OrangeTheme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/OrangeTheme.OrangeActionBar</item>
<item name="android:windowActionBar">true</item>
</style>
<style name="OrangeTheme.OrangeActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/orange</item>
<item name="background">#color/orange</item>
<item name="android:backgroundStacked">#color/orange</item>
<item name="android:backgroundSplit">#color/orange</item>
<item name="android:titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/black</item>
</style>
I have searched StackOverflow and Google, but nothing helped. I wasn't able to change the ActionBar background color.
Inside my MainActivity, I use this code:
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
I tried not to use AppCompat, but then my name has a lot of errors. It extends ActionBarActivity. If I change it to FragmentActivity I can't use getSupportActionBar() and without it my getActionBar(), is always null.
minSdkVersion 19
targetSdkVersion 21
So right now I am not able to change it. I tried renaming the parent of my style theme. I tried using andrioud:background and background. The only thing that is changing is when I use another parent like
Theme.App.Compat.Light or Theme.AppCompat.Light.DarkActionBar.
Does someone have an idea, how I could be able to change the colors and other stuff, on runtime?
With new AppCompat-v7 (v21) you can use new color theming attributes. See here.
Or alternatively you have to use <item name="actionBarStyle"> property (without prefix android).
To use background color with AppCompat, you need to also define the item name without the android: attribute.
for example:
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:background">#color/action_bar_background</item>
<item name="background">#color/action_bar_background</item> //<--background item without the android attribute
</style>
and then in your custom theme do the same thing for the custom actionbar style:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>

Custom theme of ActionBar (V7) doesn't work

I use ActionBar in my Application. And I customized my own actionbar theme as the android developer site puts. unfortunately, My style doesn't work anyway. Every time my app is runned, there is an IllegalStateException thrown. And the detail is "You need to use a Theme.AppCompat theme (or descendant) with this activity.". Then, my custom style is here:
<resources>
<!-- the theme applied to the application or activity -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#8FB01C</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#CCE96B</item>
<item name="colorAccent">#303A0A</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- the theme applied to the application or activity -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionMenuTextColor">#color/action_bar_text_color</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionMenuTextColor">#color/action_bar_text_color</item>
</style>
<!-- ActionBar theme. -->
<style name="ActionBarTheme" parent="AppTheme">
<!-- when hide or show ActionBar frequently, use this attribute. -->
<item name="windowActionBarOverlay">true</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:backgroundStacked">#drawable/actionbar_background</item>
<item name="android:backgroundSplit">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/TitleTextStyle</item>
<item name="background">#drawable/actionbar_background</item>
<item name="backgroundStacked">#drawable/actionbar_background</item>
<item name="backgroundSplit">#drawable/actionbar_background</item>
</style>
<!-- action bar title text -->
<style name="TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#400040</item>
</style>
<!-- action bar tab text -->
<style name="TabTextStyle" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#400040</item>
</style>
</resources>
And my manifest about this activity is here:
<activity
android:name=".HomeActivity"
android:label="#string/app_name"
android:launchMode="singleInstance"
android:theme="#style/ActionBarTheme"
android:uiOptions="splitActionBarWhenNarrow" >
</activity>
But the strange thing is when I set android:theme="#style/ActionBarTheme" to android:theme="#style/Theme.Appcomat.Light", it works well. But the style is not what I want. So, it does confuse me. So, I want to know why my custom style doesn't work.
Alright, After the ActionBarTheme is changed into this:
<style name="ActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="colorPrimary">#8FB01C</item>
<item name="colorPrimaryDark">#CCE96B</item>
<item name="colorAccent">#4D4DFF</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionMenuTextColor">#color/action_bar_text_color</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionMenuTextColor">#color/action_bar_text_color</item>
<item name="windowActionBarOverlay">true</item>
</style>
it works well. Yep, here:
<style name="ActionBarTheme" parent="AppTheme">
It doesn't work. So I want to know why. Can't custom style be inherited, something wrong with my dev environment, or something else?
Maybe this is just the problem of your IDE. If you are using Eclipse, project-->clean, and then select your project, OK, then your project will rebuild. If you are using Android Studio, then, Build-->Rebuild Project or Clean Project, then take a look at the result.

Resources