Android Spinner Text Color dropdown - android

I cant figure out why my text color for the spinner does not change color. Could you help with figuring this out please.
<style name="Theme.Material_Dark." parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="ActionBarThemeOverlay" parent="">
<item name="android:spinnerItemStyle">#style/SpinnerItem</item>
<item name="android:spinnerStyle">#style/SpinnerItem.DropDownItem</item>
</style>
<style name="SpinnerItem" parent="#android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">#color/actionbar_bg_dk</item>
</style>
<style name="SpinnerItem.DropDownItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#color/White</item>
<item name="android:popupBackground">#424242</item>
</style>

Create a TextView layout.
dropdown_spinner_text.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinner_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:textColor="#color/colorBlack"
android:background="#color/colorWhite"/>
Then set that as your dropdown resource.
spinnerAdapter.setDropDownViewResource(R.layout.dropdown_spinner_text);

add the the declared item style to textAppearance
<style name="ActionBarThemeOverlay" parent="">
<item name="android:spinnerItemStyle">#style/SpinnerItem</item>
</style>
<style name="SpinnerItem" parent="#android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">#color/actionbar_bg_dk</item>
<item name="android:textAppearance">#style/SpinnerItem.DropDownItem"</item>
</style>
<style name="SpinnerItem.DropDownItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#color/White</item> //drop down item text color
<item name="android:popupBackground">#424242</item>
</style>

Related

How to Change CardView background color from a theme

In an app that has multiple themes, how would you change the background color of the CardView from the styles file?
styles.xml
<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimaryTheme1</item>
<item name="colorPrimaryDark">#color/colorPrimaryDarkTheme1</item>
<item name="colorAccent">#color/colorAccentTheme1</item>
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimaryTheme2</item>
<item name="colorPrimaryDark">#color/colorPrimaryDarkTheme2</item>
<item name="colorAccent">#color/colorAccentTheme2</item>
</style>
<style name="AppTheme3" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimaryTheme3</item>
<item name="colorPrimaryDark">#color/colorPrimaryDarkTheme3</item>
<item name="colorAccent">#color/colorAccentTheme3</item>
</style>
CardView
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:elevation="4dp"
app:cardCornerRadius="15dp">
I want to change the background color for each theme and I'm hoping to accomplish this in the styles.xml file.
Try the below line of code
Write the below line of code in style.xml
<style name="CustomCardview1" parent="CardView">
<item name="cardBackgroundColor">#F3921F</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">10dp</item>
</style>
<style name="CustomCardview2" parent="CardView">
<item name="cardBackgroundColor">#F3931F</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">10dp</item>
</style>
Write the below line of code in layout where you need the cardview
<android.support.v7.widget.CardView
style="#style/CustomCardview">
hope it will help for you

TextInputLayout outline hint color

I have a strange bug on a TextInputLayout. The color of the hint of the com.google.android.material.textfield.TextInputEditText goes white on focus.
this is how I am setting it:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/inputEmail"
style="#style/EditText.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
app:boxStrokeColor="#color/colorBrand">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:hint="#string/edt_hint_email"
android:inputType="textEmailAddress"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
..and this is the style:
<style name="EditText.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:minHeight">56dp</item>
<item name="android:textSize">18sp</item>
<item name="android:fontFamily">#font/dubai_regular</item>
<item name="hintEnabled">true</item>
</style>
edit: add style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextAppearance.AppCompat.Title" parent="TextAppearance.AppCompat.Large">
<item name="android:textColor">#color/colorTextPrimary</item>
<item name="android:layout_gravity">center_vertical</item>
</style>
<style name="EditText.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:minHeight">56dp</item>
<item name="android:textSize">18sp</item>
<item name="android:fontFamily">#font/dubai_regular</item>
<item name="hintEnabled">true</item>
</style>
<style name="Button" parent="Widget.MaterialComponents.Button">
<item name="cornerRadius">10dp</item>
<item name="backgroundTint">#color/colorAccent</item>
<item name="android:minHeight">56dp</item>
<item name="android:textAllCaps">false</item>
<item name="android:fontFamily">#font/dubai_bold</item>
<item name="android:elevation">0dp</item>
<item name="android:stateListAnimator">#null</item>
</style>
<style name="Button.Primary">
<item name="backgroundTint">#color/colorAccent</item>
</style>
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">#anim/slide_up_dialog</item>
<item name="android:windowExitAnimation">#anim/slide_out_down</item>
</style>
<style name="Tag" parent="TextAppearance.AppCompat">
<item name="android:background">#drawable/tag_navy</item>
<item name="android:fontFamily">#font/dubai_bold</item>
<item name="android:textSize">12sp</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="android:paddingTop">6dp</item>
<item name="android:paddingBottom">6dp</item>
<item name="android:gravity">center</item>
<item name="android:textColor">#color/colorWhite</item>
</style>
<style name="Tag.Closed">
<item name="android:background">#drawable/ic_tag_closed</item>
<item name="android:textAllCaps">true</item>
</style>
<style name="Tab.TextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textSize">14sp</item>
<item name="android:fontFamily">#font/dubai_bold</item>
</style>
</resources>
Just Add Hint text color inside your EditText.OutlinedBox style.
TextInputLayout have specified the property for changing the color of hint and error.
<item name="android:textColorHint"> #Your Color </item>
<item name="hintTextColor"> #Your Color </item>
Here I have two different Hint Text color specified
1) android:textColorHint and 2) hintTextColor
Because this both works differently.
android:textColorHint property will handle the text color of hint of the EditText.
hintTextColor property will handle the text color of hint on the outline box.
Try app:hintTextAppearance="#style/hintText" for TextInputLayout
<style name="hintText" parent="android:TextAppearance">
<item name="android:textColor">your color</item>
</style>

Handles of EditText are underlined

I encountered a problem recently, which was to change the default underline bar of an edittext from a default blackish color to white.
I used this solution, which seemed to me the best practices by changing the style of the EditText :
EditText
<android.support.v7.widget.AppCompatEditText
android:id="#+id/nom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/Activity_Main_EditText_Nom"
android:imeOptions="actionNext"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:textColor="#android:color/white"
android:textColorHint="#color/activityBackground"
android:theme="#style/EditTextStyle"
android:visibility="gone"
/>
style.xml
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDisablePreview">true</item>
<item name="android:windowBackground">#color/activityBackground</item>
<item name="windowActionBar">false</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
<item name="colorControlNormal">#android:color/white</item>
<item name="colorControlActivated">#color/colorAccent</item>
<item name="colorControlHighlight">#color/colorAccent</item>
</style>
It worked ! But it also added to the handles of the EditText an underline bar...
Any ideas ?
Answer
By discussing with #rafsanahmad007, we finally got to a final solution.
style.xml
<resources>
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDisablePreview">true</item>
<item name="android:windowBackground">#color/activityBackground</item>
<item name="windowActionBar">false</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MyTheme.EditText" parent="MyTheme">
<item name="colorControlNormal">#android:color/white</item>
<item name="colorControlActivated">#color/colorAccent</item>
<item name="colorControlHighlight">#color/colorAccent</item>
</style>
</resources>
Apply MyTheme to application, as usual. When you want to tweak an EditText just add to it :
EditText
<EditText
...
android:theme="#style/MyTheme.EditText"
...
/>
Problem is with your style themes.. parent
use below code:
<android.support.v7.widget.AppCompatEditText
android:theme="#style/MyStyle.EditText"/>
Now in your styles.xml
<style name="MyStyle.EditText">
<item name="editTextStyle">#style/MyEditTextStyle</item>
</style>
<style name="MyEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="colorControlNormal">#android:color/white</item>
<item name="colorControlActivated">#color/colorAccent</item>
<item name="colorControlHighlight">#color/colorAccent</item>
</style>
try not to use the theme parent directly
EDIT
add the color property in base theme also
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#android:color/white</item>
<item name="colorControlActivated">#color/colorAccent</item>
<item name="colorControlHighlight">#color/colorAccent</item>
</style>
make sure you select the theme in your activity in manifest...
Use this doc.I think this URL will helpfull for your problem.
http://www.materialdoc.com/edit-text/

Can't inherit button color on style

I am trying to define button properties on style.
My code is
<style name="button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
And using as
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"
style="#style/button"/>
But the color of the button's normal state is not changing.
This button style is only for some buttons. Not for all butons.
What to do now?
edit after question clarification
Save you style.xml in res/values/
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="custom_button" parent="#android:style/Widget.Button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
Apply it like so:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"
style="#style/custom_button"/>
first answer
You need to inherit the parent style.
<style name="Button" parent="#android:style/Widget.Button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
That way all your Button's that are not styled will have your custom style. i.e. no need to put in the style value.
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"/>

Changing menu background of toolbar with material design

Hi I want to change the style of my menu background, with the popupTheme it doesnt change
My toolbar code
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/fondoNavigation"
android:theme="#style/CustomToolbar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
My Style
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/fondoNavigation</item>
<item name="colorAccent">#color/letraNavigation</item>
</style>
<style name="CustomToolbar" parent="#style/ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#color/letraNavigation</item>
<item name="android:textColorSecondary">#color/letraNavigation</item>
</style>
My v21 Style
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">#color/fondoNavigation</item>
<item name="android:colorAccent">#color/letraNavigation</item>
<item name="android:textColorPrimary">#color/fondoNavigation</item>
</style>
<style name="Theme.Dbtools_style" parent="#style/Theme.AppCompat.Light">
<!-- Title Text Color -->
<item name="actionMenuTextColor">#color/DimGray</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:dropDownListViewStyle">#style/PopupMenuListView</item>
</style>
<style name="PopupMenuListView" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:divider">#color/DarkGray</item>
<item name="android:dividerHeight">0.5dp</item>
<item name="android:background">#color/White</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/title_bar</item>
<item name="background">#color/title_bar</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="android:subtitleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="subtitleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
With this one I changed the background and others things
<style name="CustomToolbar" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#color/letraNavigation</item>
<item name="android:textColorSecondary">#color/letraNavigation</item>
<item name="android:popupBackground">#color/fondoNavigation</item>
<item name="android:background">#color/fondoNavigation</item>
</style>
Solution for people not using Support Library
<Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:paddingTop="30dp"
android:background="#e53935"
android:elevation="4dp"
android:theme="#style/ToolbarTheme"
android:popupTheme="#style/ToolbarPopUpTheme"/>
styles.xml
<style name="ToolbarTheme" parent="android:Theme.Material" />
<style name="ToolbarPopUpTheme" parent="android:Theme.Material.Light"/>

Categories

Resources