Spinner drop down menu items color (Android) - android-spinner

So I have a spinner and I was successful in changing the color of the selected item but I am not able to change the color of the items in the drop down menu
This is my spinner_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:textColor="#33CCFF"
/>
and this is my styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Light" >
<item name="android:spinnerDropDownItemStyle">#style/SpinnerItem.DropDownItem.Color</item>
<item name="android:spinnerItemStyle">#style/SpinnerItem</item>
</style>
<style name="SpinnerItem.DropDownItem.Color" parent="#android:style/Widget.DropDownItem.Spinner">
<item name="android:textColor">#4FBDE8</item>
</style>
<style name="SpinnerItem" parent="#android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">#4FBDE8</item>
</style>
</resources>
is there an XML way I can do it in ?

Here is the solution I found on another stackoverflow thread
<style name="Theme.NoTitleBar.WithColoredSpinners" parent="#android:style/Theme.NoTitleBar">
<item name="android:spinnerItemStyle">#style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerItem.DropDownItem</item>
</style>
<style name="SpinnerItem" parent="#android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">#00FF00</item>
</style>
<style name="SpinnerItem.DropDownItem" parent="#android:style/Widget.DropDownItem.Spinner">
<item name="android:textColor">#FF0000</item>
</style>

While specifying a layout resource file for the spinner, you have to set it at two places.
While declaring a new ArrayAdapter
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, categories);
While setting the dropDownViewResource on the array adapter.
dataAdapter.setDropDownViewResource(R.layout.spinner_item_dropdown);
Notice that two different layout files have been used. You can customize your views in the following manner, by defining the styles and using these styles as theme in the respective layouts.
<style name="SpinnerItem" parent="#android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">#color/white</item>
<item name="android:background">#color/black</item>
</style>
<style name="SpinnerItem.DropDownItem" parent="#android:style/Widget.DropDownItem.Spinner">
<item name="android:textColor">#color/black</item>
</style>
Hope this helps.

Related

android studio styles.xml cannot servolve symbol

I made new style in styles.xml file and am trying to use it at the TextView objects in activity_main.xml file but I keep getting error: cannot resolve flag. What's wrong? I was trying to make other styles and it's the same error.
Styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#ff0000</item>
<item name="colorPrimaryDark">#ffffff</item>
<item name="colorAccent">#19df19</item>
</style>
<style name="pytanie">
<item name="android:textSize">20sp</item>
<item name="android:textAllCaps">true</item>
<item name="android:textStyle">italic</item>
<item name="android:textColor">000000</item>
<item name="android:textColorHighlight">#ff0000</item>
</style>
In main_activity.xml:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="pytanie numer 1"
android:textStyle="#styles/pytanie"/>

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>

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

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

Resources