New to AS. Trying to use MaterialButton, overriding default background with #drawable, but it's not working.
Environment
Android Studio: 4.0
Dependencies:
implementation "androidx.appcompat:appcompat:$dependency_version_appcompat"
implementation "com.google.android.material:material:$dependency_version_material"
Drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shape="rectangle">
<solid
app:backgroundTint ="?attr/ColorBackgroundAppBar">
</solid>
<stroke
android:width="1px"
android:color="?attr/ColorBorderDark">
</stroke>
</shape>
Layout
<com.google.android.material.button.MaterialButton
android:id="#+id/common_appbar_btn_lang_mode"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background = "#drawable/common_appbar_btn_background"
android:elevation="#dimen/common_elevation_height_btn"
... />
With the above, I just get the default MaterialButton background.
If I set backgroundTint to #null
<com.google.android.material.button.MaterialButton
android:id="#+id/common_appbar_btn_lang_mode"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
app:backgroundTint="#null"
android:background = "#drawable/common_appbar_btn_background"
android:elevation="#dimen/common_elevation_height_btn"
... />
With the above, the drawable specs are recognized, but if I change the theme style, that doesn't work.
These are the only settings that work:
<com.google.android.material.button.MaterialButton
android:id="#+id/common_appbar_btn_lang_mode"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:backgroundTint = "?attr/ColorBackgroundAppBar"
app:strokeColor="?attr/ColorBackgroundAppBar"
app:strokeWidth="0px"
android:elevation="#dimen/common_elevation_height_none"
android:fontFamily="#font/font_family_kaiti"
android:text="简"
android:textAlignment="center"
android:textColor="?attr/ColorTextPrimary"
android:textStyle="normal"
android:textFontWeight="700"
android:textSize="24dp" />
Am I doing sth wrong...or is MaterialButton not quite there yet? I can live with the last solution, but it increases maintenance...
Define you app theme using Theme.MaterialComponents.DayNight:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryVariant">#color/colorPrimaryLight</item>
<item name="colorSecondary">#color/colorSecondary</item>
<!-- .... -->
</style>
Then, if you need, define the colors for the light and dark mode:
Example: res\values\colors.xml:
<color name="colorPrimary">.....</color>
In res\values-night\colors.xml folders define the same color:
<color name="colorPrimary">.....</color>
Finally define a style for your button (you don't need 2 different styles for dark and light mode):
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
<item name="backgroundTint">#color/....</item>
<item name="strokeColor">#color/....</item>
<item name="strokeWidth">#dimen/....</item>
</style>
Last step assign the style to the Button in the layout.
<com.google.android.material.button.MaterialButton
style="#style/Widget.App.Button"
.../>
or globally in your app theme:
<item name="materialButtonStyle">#style/Widget.App.Button</item>
For your Button since you are not using a gradient you can use the standard attributes provided by the MaterialButton.
If you prefer to use the android:background attribute with a custom drawable you can use:
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
<item name="backgroundTint">#null</item>
<item name="android:background">#drawable/.....</item>
</style>
Then inside the drawable just use the colors or attributes defined in the app theme and in the res\values\colors.xml and res\values-night\colors.xml folders.
I'm placing a TextInputEditText widget onto a white background. When the fragment first loads, the widget does not have focus. The border around the widget is white (or almost white), so it is invisible on a white background. Here is a screenshot of that widget, drawn on a black background for contrast:
As soon as I tap on the widget, the border becomes that of my primary color, which is exactly what I want. Here is a similar screenshot after the widget is activated.
I'm trying to control these colors through a style, and I've tried everything that I can think of, but I cannot figure out how to adjust that color. Here is my style (feel free to laugh at the various attempts):
<style name="MyTextInputLayout" parent="Base.Widget.MaterialComponents.TextInputLayout">
<item name="android:colorBackground">#android:color/black</item>
<item name="android:textColorHint">#color/colorPrimary</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="android:colorControlActivated">#android:color/black</item>
<item name="android:colorControlNormal">#android:color/black</item>
<item name="android:colorControlHighlight">#android:color/black</item>
<item name="android:backgroundTint">#android:color/black</item>
<item name="android:colorAccent">#android:color/black</item>
</style>
<style name="MyTextInputEditText" parent="ThemeOverlay.MaterialComponents.TextInputEditText">
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#android:color/black</item>
<item name="android:colorControlActivated">#android:color/black</item>
<item name="android:colorControlNormal">#android:color/black</item>
<item name="android:colorControlHighlight">#android:color/black</item>
<item name="android:backgroundTint">#android:color/black</item>
<item name="android:colorAccent">#android:color/black</item>
</style>
And finally, the xml of the layout in case it is helpful:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="#style/MyTextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/reg_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/username"
style="#style/MyTextInputEditText"/>
</com.google.android.material.textfield.TextInputLayout>
How can I change this border color when the widget is not active (i.e. does not have focus)?
I solved this in two main steps:
First problem I had was that the parent style for my TextInputLayout style needed to be changed to Widget.MaterialComponents.TextInputLayout.OutlinedBox.
Once I figured that out, I traced through the Android xml for that style and got to a file called mtrl_box_stroke_color.xml. This is a selector where the three colors for the standard TextInputLayout border are declared. That file looks like this:
So I copied that and created my own file in the res/color folder that I called edit_text_box_border.xml. I modified the three colors to suit my purposes, ultimately coming up with this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_focused="true"/>
<item android:alpha="0.87" android:color="#color/colorPrimary" android:state_hovered="true"/>
<item android:alpha="0.12" android:color="#color/colorPrimary" android:state_enabled="false"/>
<item android:alpha="0.38" android:color="#color/colorPrimary"/>
</selector>
Then, back in my style, I had to get rid of my many color attempts and add an item for boxStrokeColor that pointed to this file. Here are both styles:
<style name="MyTextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:textColorHint">#color/colorPrimary</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="boxStrokeColor">#color/edit_text_box_border</item>
</style>
<style name="MyTextInputEditText" parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox.Dense">
<item name="android:textColor">#android:color/black</item>
</style>
Now, when I run the app, I start out with this:
Which then turns into this when I tap on it:
That's what I was going for, so problem solved. Hope this helps someone.
1.
<com.google.android.material.textfield.TextInputLayout
...
style="#style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
app:boxStrokeColor = "#android:color/holo_purple"
//border color when in active status
...
2. add the following in colors.xml file
<color name="mtrl_textinput_default_box_stroke_color">#00ff00</color>
//border color when in inactive status
Add
app:boxStrokeColor="#color/black"
app:hintTextColor="#color/black"
to your XML file. I tried all the color options. You can replace the "#color/black" with any color HEX code. Also write app:color and android will show you all the color options, there are many color fields that can be changed, like the error field which we can set to red to indicate the user has entered Invalid Data.
In case you need to change the outline color dynamically (for automatic field validation, for example) you can use the following hack:
Set
app:errorTextColor="#color/colorAccepted"
app:errorIconTint="#color/colorAccepted"
for TextInputLayout in xml.
Then in code:
text_input_layout.errorIconDrawable = null to remove the error icon
and text_input_layout.error = " " to enable the coloring or text_input_layout.error = null to disable it.
This way TextInputLayout takes more space. To resolve this you can customize the errorTextAppearance by defining your own style:
<style name="ErrorTextStyle" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textSize">0sp</item>
</style>
Note:
That's clearly a hack rather than a proper solution.
I use this:
<style name="TextInputLayoutTheme" parent="TextAppearance.AppCompat">
<item name="android:textColorHint">#color/secondaryTextLight</item>
<item name="android:backgroundTint" tools:targetApi="lollipop">#color/colorAccent</item>
<item name="android:textColor">#color/white</item>
<item name="colorControlActivated">#color/colorAccent</item>
</style>
and in the xml:
<com.google.android.material.textfield.TextInputEditText
style="#style/TextInputLayoutTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I've been trying various ways to do this through styles but cannot get what I want. It seems I can have a coloured button with a shadow or a button with no shadow for which I can only change the text and pressed colours.
Here's what I have in my styles.xml:
<style name="PrimaryFlatButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#color/colorPrimary</item>
<item name="colorButtonNormal">#color/colorPrimaryLight</item>
</style>
and here is what I have in my layout:
<Button
android:id="#+id/btn_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/pc_large_padding"
android:theme="#style/PrimaryFlatButton"
style="#style/Widget.AppCompat.Button"
android:text="Search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
Which gives me a coloured button which darkens when pressed but has a shadow.
If I change the button to have a style of:
style="#style/Widget.AppCompat.Button.Borderless"
Then I successfully lose the shadow but get no background colour unless the button is pressed. I presume Android's idea of "borderless" means having nothing to indicate a border at all - just plain text - rather than making a flat button.
All I want is the standard themed button, with a background colour, which changes colour when pressed, and has no shadow.
You should be able to get a colored button complete with the ripple effect by creating a selector drawable and specifying it as the button's background. Something like this:
some_layout.xml
<Button
style="#style/Theme.Flat.Button"
<!-- Any other properties you want to set -->
/>
style.xml
<style name="Theme.Flat.Button" parent="#style/Widget.AppCompat.Button.Borderless">
<item name="android:background">#drawable/ripple_selector</item>
<!-- Any other items you want to add -->
</style>
ripple_selector.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/colorPrimary">
<item>
<selector>
<item android:state_enabled="false">
<color android:color="#color/colorPrimaryLight" />
</item>
<item android:state_enabled="true" android:state_pressed="false">
<color android:color="#color/colorPrimaryLight" />
</item>
<item android:state_enabled="true" android:state_pressed="true">
<color android:color="#color/colorPrimary" />
</item>
</selector>
</item>
</ripple>
You can remove the elevation/shadow by adding android:stateListAnimator="#null" to your button's XML properties.
Full button XML:
<Button
android:id="#+id/btn_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/pc_large_padding"
android:theme="#style/PrimaryFlatButton"
style="#style/Widget.AppCompat.Button"
android:text="Search"
android:stateListAnimator="#null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
You can also drop this line into your styles.xml in order to avoid adding it to every single one of your buttons
styles.xml:
<style name="PrimaryFlatButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#color/colorPrimary</item>
<item name="colorButtonNormal">#color/colorPrimaryLight</item>
<item name="android:stateListAnimator">#null</item>
</style>
Michael's answer is also technically correct. If you would like more fine-tuned control over the styling and states of your buttons (including elevation/shadows), you can look into creating your own StateListDrawable resources for your buttons. Since you seem more interested in using the default button styling with only slight modifications, I won't go into further detail about StateListDrawables here. However, if you're interested, you can read Michael's answer as well as the StateListDrawable documentation here.
I am creating an EditText in my layout xml file
But I want to change color line in EditText from Holo to (for example) red.
How that can be done?
This is the best tool that you can use for all views and its FREE many thanks to #Jérôme Van Der Linden.
The Android Holo Colors Generator allows you to easily create Android components such as EditText or spinner with your own colours for your Android application. It will generate all necessary nine patch assets plus associated XML drawable and styles which you can copy straight into your project.
http://android-holo-colors.com/
UPDATE 1
This domain seems expired but the project is an open source you can find here
https://github.com/jeromevdl/android-holo-colors
try it
this image put in the background of EditText
android:background="#drawable/textfield_activated"
UPDATE 2
For API 21 or higher, you can use android:backgroundTint
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
android:backgroundTint="#android:color/holo_red_light" />
Update 3
Now We have with back support AppCompatEditText
Note: We need to use app:backgroundTint instead of android:backgroundTint
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Underline color change"
app:backgroundTint="#color/blue_gray_light" />
Update 4
AndroidX version
<androidx.appcompat.widget.AppCompatEditText
app:backgroundTint="#color/blue_gray_light" />
I don't like previous answers. The best solution is to use:
<android.support.v7.widget.AppCompatEditText
app:backgroundTint="#color/blue_gray_light" />
android:backgroundTint for EditText works only on API21+ . Because of it, we have to use the support library and AppCompatEditText.
Note: we have to use app:backgroundTint instead of android:backgroundTint
AndroidX version
<androidx.appcompat.widget.AppCompatEditText
app:backgroundTint="#color/blue_gray_light" />
You can also quickly change the EditText's underline color by tinting the background of the EditText like so:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Something or Other"
android:backgroundTint="#android:color/holo_green_light" />
for API below 21, you can use theme attribute in EditText
put below code into style file
<style name="MyEditTextTheme">
<item name="colorControlNormal">#FFFFFF</item>
<item name="colorControlActivated">#FFFFFF</item>
<item name="colorControlHighlight">#FFFFFF</item>
</style>
use this style in EditText as
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="#dimen/user_input_field_height"
android:layout_marginTop="40dp"
android:hint="#string/password_hint"
android:theme="#style/MyEditTextTheme"
android:singleLine="true" />
Programmatically, you can try:
editText.getBackground().mutate().setColorFilter(getResources().getColor(android.R.color.holo_red_light), PorterDuff.Mode.SRC_ATOP);
Its pretty simple (Required: Minimum API 21)...
Go to your xml and select the EditText field
On the right side, you can see the 'Attributes' window. Select 'View All Attributes'
Just search for 'tint'
And add/change the 'backgroundTint' to a desired color hex (say #FF0000)
Keep Coding........ :)
You can change the color of EditText programmatically just using this line of code:edittext.setBackgroundTintList(ColorStateList.valueOf(yourcolor));
i think the best way is by theme:
<style name="MyEditTextTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#color/black</item>
<item name="colorControlActivated">#color/action_blue</item>
<item name="colorControlHighlight">#color/action_blue</item>
</style>
<style name="AddressBookStyle" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">13sp</item>
<item name="android:theme">#style/MyEditTextTheme</item>
</style>
<android.support.v7.widget.AppCompatEditText
style="#style/AddressBookStyle"/>
To change Edittext’s underline color:
If you want the entire app to share this style, then you can do the following way.
(1) go to styles.xml file. Your AppTheme that inherits the parent of Theme.AppCompat.Light.DarkActionBar (in my case) will be the base parent of all they style files in your app. Change the name of it to “AppBaseTheme’. Make another style right under it that has the name of AppTheme and inherits from AppBaseTheme that you just edited. It will look like following:
<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<!--see http://www.google.com/design/spec/style/color.html#color-color-palette-->
<item name="colorPrimary">#color/material_brown_500</item>
<item name="colorPrimaryDark">#color/material_brown_700</item>
<item name="colorAccent">#color/flamingo</item>
<style name="AppTheme" parent="AppBaseTheme">
<!-- Customize your theme here. -->
</style>
Then change the “colorAccent” to whatever the color you want your EditText line color to be.
(2) If you have other values folders with style.xml, this step is very important. Because that file will inherit from your previous parent xml file. For example, I have values-19/styles.xml. This is specifically for Kitkat and above. Change its parent to AppBaseTheme and make sure to get rid of “colorAccent” so that it doesn’t override the parent’s color. Also you need to keep the items that are specific to version 19. Then it will look like this.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
The line's color is defined by EditText's background property. To change it you should change the android:background in the layout file.
I should note that this style is achieved by using a 9-patch drawable. If you look in the SDK, you can see that the background of the EditText is this image:
To change it you could open it in an image manipulation program and color it in desired color. Save it as bg_edit_text.9.png and then put it in you drawable folder. Now you can apply it as a background for your EditText like so:
android:background="#drawable/bg_edit_text"
drawable/bg_edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape>
<solid android:color="#android:color/transparent" />
<stroke
android:width="1dp"
android:color="#color/colorDivider" />
</shape>
</item>
</layer-list>
Set to EditText
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_edittext"/>
The background of widgets are API level dependent.
ALTERNATIVE 1
You can provide a custom image to your EditText background by
android:background="#drawable/custom_editText"
Your image should look something like this. It will give you the desired effect.
ALTERNATIVE 2
Set this xml to your EditText background attribute.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#4C000000"/>
<corners android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
This will have the same look and feel of your EditText on every API.
You can change the color with tinting the background
<EditText
android:backgroundTint="#color/red"/>
in xml layout use:
android:backgroundTint="#color/colorPrimary"
or in java code copy this method:
public void changeLineColorInEditText(EditText editText, int color) {
editText.setBackgroundTintList(ColorStateList.valueOf(color));
}
and use it like this:
changeLineColorInEditText(editText, getResources().getColor(R.color.colorPrimary));
Use this method.. and modify it according to ur view names. This code works great.
private boolean validateMobilenumber() {
if (mobilenumber.getText().toString().trim().isEmpty() || mobilenumber.getText().toString().length() < 10) {
input_layout_mobilenumber.setErrorEnabled(true);
input_layout_mobilenumber.setError(getString(R.string.err_msg_mobilenumber));
// requestFocus(mobilenumber);
return false;
} else {
input_layout_mobilenumber.setError(null);
input_layout_mobilenumber.setErrorEnabled(false);
mobilenumber.setBackground(mobilenumber.getBackground().getConstantState().newDrawable());
}
If you want a flat line, you can do this easily with xml. Here is the xml example:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="-1dp"
android:left="-1dp"
android:right="-1dp"
android:bottom="1dp"
>
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#6A9A3A"/>
</shape>
</item>
</layer-list>
Replace the shape with a selector if you want to provide different width and color for focused edittext.
The best approach is to use an AppCompatEditText with backgroundTint attribute of app namespace. i.e.
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
app:backgroundTint="YOUR COLOR"
android:layout_height="wrap_content" />
when we use android:backgroundTint it will only work in API21 or more but app:backgroundTint works on all API levels your app does.
You can do it dynamically if you have custom class for edittext.
First of all you have declare state and color of edittext given below.
int[][] states = new int[][]{
new int[]{-android.R.attr.state_focused}, // enabled
new int[]{android.R.attr.state_focused}, // disabled
};
int[] colors = new int[]{
secondaryColor,
primaryColor,
};
Then Create ColorStateList variable with that
ColorStateList myList = new ColorStateList(states, colors);
Then last step is to assign it to edittext.
editText.setBackgroundTintList(myList);
After this you have to written on focused change event.
this.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
setUnderlineColor(selectionColor,deselectionColor);
}
});
And you can make above code inside setUnderlineClor() Method,
private void setUnderlineColor(int primaryColor, int secondaryColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int[][] states = new int[][]{
new int[]{-android.R.attr.state_focused}, // enabled
new int[]{android.R.attr.state_focused}, // disabled
};
int[] colors = new int[]{
secondaryColor,
primaryColor,
};
ColorStateList myList = new ColorStateList(states, colors);
setBackgroundTintList(myList);
}
}
Use android:background property for that edittext. Pass your drawable folder image to it.
For example,
android:background="#drawable/abc.png"
<EditText
android:id="#+id/et_password_tlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:textColorHint="#9e9e9e"
android:backgroundTint="#000"
android:singleLine="true"
android:drawableTint="#FF4081"
android:paddingTop="25dp"
android:textColor="#000"
android:paddingBottom="5dp"
android:inputType="textPassword"/>
<View
android:id="#+id/UnderLine"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/et_password_tlay"
android:layout_centerHorizontal="true"
android:background="#03f94e" />
**it one of doing with view **
Try the following way, it will convert the bottom line color of EditText, when used as a background property.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="#dimen/spacing_neg"
android:right="#dimen/spacing_neg"
android:top="#dimen/spacing_neg">
<shape>
<solid android:color="#android:color/transparent" />
<stroke
android:width="#dimen/spacing_1"
android:color="#android:color/black" />
</shape>
</item>
</layer-list>
This can simply be done by including this android:theme="#style/AppTheme.AppBarOverlay as attribute in for your editText
and add this <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> to your styles
This is a pretty specific question. I have a spinner on an ActionBar that is added in the onCreate() method. I have been able to style the text white, but I can't get the underline and the triangle/arrow at the bottom right to appear as white. Here is my styling:
<item name="android:actionDropDownStyle">#style/customActionBarDropDownStyle</item>
<style name="customActionBarDropDownStyle" parent="android:style/Widget.Holo.Light.Spinner">
<item name="android:textColor">#FFFFFF</item>
</style>
I can't find a style item/property that makes the underline and triangle white. Does one exists?
Here's an example. I have highlighted in red the triangle and underline that I want to make white.
A bit late answer, but better than never :)
You should create a new 9 patch drawable and set it as a background to android:actionDropDownStyle.
here is an example:
<item name="android:actionDropDownStyle">#style/customActionBarDropDownStyle</item>
<style name="customActionBarDropDownStyle"parent="android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/custom_spinner_dropdown</item>
</style>
You can't set a color to almost every native component, as their backgrounds are (in most cases) 9-patch pngs.
The actionDropDownStyle can not used to change the style of spinner you added on actionbar; its for one of the actionbar mode ActionBar.NAVIGATION_MODE_LIST;
As for your problem, you can define a selector for your spinner in the layout file,just like this:
enter code here
<Spinner
android:dropDownWidth="200dp"
android:background="#drawable/actionbar_spinner"
android:id="#+id/action_spinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="10dp" />
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:drawable="#drawable/spinner_ab_disabled" />
<item android:state_pressed="true"
android:drawable="#drawable/spinner_ab_pressed" />
<item android:state_pressed="false" android:state_focused="true"
android:drawable="#drawable/spinner_ab_focused" />
<item android:drawable="#drawable/spinner_ab_default" />
</selector>
Try this : android:background="#null"