My problem is that I don't know how to change underline color of EditText - I have LG Nexus 5 (Android 6).
I would like to change normal underline color to white. I used all params like (style):
colorControlNormal
colorControlActivated
colorControlHighlight
textColorSecondary
colorPrimary
colorPrimaryDark
e.g.
<style name="FormFont" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">#dimen/form_text_size</item>
<item name="colorControlNormal">#c5c5c5</item>
</style>
but nothing seems to work (it only changes color when EditText us focused like in above pic).
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">#color/accent</item>
<item name="colorControlHighlight">#color/accent</item>
</style>
The most efficient thing to do is to add the colorAccent attribute in your AppTheme style like this:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#color/colorAccent</item>
<item name="android:editTextStyle">#style/EditTextStyle</item>
</style>
<style name="EditTextStyle" parent="Widget.AppCompat.EditText"/>
The colorAccent attribute is used for widget tinting throughout the app and thus should be used for consistency
Try using android:backgroundTint="#yourUnderlineColor".
Only available for API 21 and higher.
To make it work in Android 6, create your custom theme in
res/values-v21/styles.xml .
<style name="FormFont" parent="#android:style/TextAppearance.Medium">
<item name="colorControlNormal">#c5c5c5</item>
</style>
<style name="FormFontWhite" parent="#android:style/TextAppearance.Medium">
<item name="colorControlNormal">#ffffff</item>
</style>
and apply then in your EditText
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/FormFont"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/FormFontWhite"/>
For more info check #reVerse answer .
Hope this helps!
<android.support.v7.widget.AppCompatEditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/cux_label_password"
android:inputType="textPassword"
app:theme="#style/editTextStyle" />
<style name="editTextStyle" parent="TextAppearance.AppCompat">
<item name="colorControlNormal">#FFFFFF</item>
<item name="colorControlActivated">#FFFFFF</item>
<item name="colorControlHighlight">#FFFFFF</item>
</style>
Related
Style.xml File(AppTheme is the theme of my app and it is inheriting materiallightdarkactionbar theme)
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorForeground">#color/holo_orange_light</item>
<item name="android:buttonStyle">#style/newbuttonstyle</item>
</style>
<style name="newbuttonstyle" parent="#android:style/Widget.Button">
<item name="android:backgroundTint">#acd9e6</item>
</style>
</resources>
I am designing a calculator and this is the keypad for it.....rather than individually setting background tint for all the buttons I want to change the style of all my buttons in one go using style.xml....can i do so?
In this I am using buttonStyle and still it is not working
<item name="android:buttonStyle">#style/newbuttonstyle</item>
in your XML file
<Button
style="#style/MyButtonStyle"
android:id="#+id/btnSignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="my button"/>
in style.xml file add this code.
<style name="ButtonStyle" parent="#android:style/Widget.Button">
<item name="android:layout_width">fill_parent</item>
<item name="android:textColor">#color/black</item>
<item name="android:textSize">15sp</item>
<item name="android:padding">10dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#color/colorPrimary</item>
<item name="android:gravity">center</item>
</style>
change Style items as per your requirements.
<style name="newbuttonstyle" parent="#android:style/Widget.Button">
<item name="android:background">#acd9e6</item>
</style>
I am using above code in my application and its working fine.i think set background instead of backgroundTint.
May be its working .
check this link:
ReferenceLink
and its some issue in tintbackground in lolipop.so you have to check in below lolipop.
You can follow this question, hope it will be work for you and clear your style portion:
Android Material Design Button Styles
So I have a spinner that I'm trying to apply a style to. I have a activity theme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
And a spinner
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/entries"
I want the text of the spinner items to appear as white and to do so with xml styling. If I set android:textColor in AppTheme, everything works fine.
However this applies to other elements as well.
I have tried the following attribues in AppTheme. None of them have worked.
<item name="android:spinnerDropDownItemStyle">#style/SpinnerItem</item>
<item name="android:dropDownItemStyle">#style/SpinnerItem</item>
<item name="android:spinnerItemStyle">#style/SpinnerItem</item>
<style name="SpinnerItem">
<item name="android:textColor">#android:color/white</item>
</style>
Any help is appreciated.
You can change your AppTheme like this:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:spinnerStyle">#style/AppTheme.Spinner</item>
<item name="android:spinnerDropDownItemStyle">#style/AppTheme.DropDownSpinner</item>
</style>
<style name="AppTheme.Spinner" parent="Widget.AppCompat.Spinner">
<item name="android:textColor">#color/white</item>
</style>
<style name="AppTheme.DropDownSpinner" parent="Widget.AppCompat.DropDownItem.Spinner">
<item name="android:textColor">#color/white</item>
</style>
I want to change TextInputLayout float hint text. Here is the solution I tried:
style.xml:
<style name="TextAppearence.App.TextInputLayout" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/colorPrimary</item>
</style>
layout.xml:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/TextAppearence.App.TextInputLayout">
It works fine for some parts of app but not changes the hint color of some activities or fragments. I wonder How is it possible that a piece of code can effect some activities but not on the others.
Any idea?
Add <item name="colorAccent">#color/theme_color_blue</item> line in your style.xml like this
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/theme_color_blue</item>
<item name="colorAccent">#color/theme_color_blue</item>
<item name="android:textColorPrimary">#color/colorTextPrimary</item>
<item name="android:textColorSecondary">#color/colorTextSecondary</item>
</style>
you should use textColorHint item for your AppTheme style:
<item name="android:textColorHint">#color/yourcolor</item>
I've define a Style for the button
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:fontFamily">sans-serif</item>
<item name="android:windowBackground">#color/background</item>
<item name="android:buttonStyle">#style/AppTheme.Button</item>
<item name="android:textViewStyle">#style/AppTheme.TextView</item>
<item name="android:editTextStyle">#style/AppTheme.EditText</item>
<item name="android:checkboxStyle">#style/AppTheme.CheckBox</item>
</style>
button style:
<style name="AppTheme.Button" parent="android:Widget.Button">
<item name="android:background">#drawable/button_background</item>
<item name="android:textColor">#color/white</item>
<item name="android:textSize">#dimen/normal_text</item>
</style>
I can see it properly on the Android Studio preview, but doesn't work on device. It works on device if I set it in the element inside the layout.
<Button
android:id="#+id/btn_login"
style="#style/AppTheme.Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="LOGIN"/>
I just want to define it in the AppTheme
It's a bug, they will fix it in the new release of the AppCompat.
More info: https://code.google.com/p/android/issues/detail?id=170476
This is how I set my buttons.
<Button
android:id="#+id/button_login"
style="#style/ButtonStyle"
android:text="#string/button_login" />
This is my style on values folder.
<style name="ButtonStyle" parent="ButtonStyleBase" />
<style name="ButtonStyleBase">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">#dimen/padding</item>
<item name="android:textSize">#dimen/font_regular</item>
<item name="android:textColor">#color/text_regular</item>
<item name="android:background">#drawable/shape_clickable</item>
</style>
And this is my style on values-v21 folder
<style name="ButtonStyle" parent="ButtonStyleBase">
<item name="textAllCaps">false</item>
<item name="android:textColor">#000000</item>
</style>
But the text is always uppercase on buttons. If I set it directly on the button it will get back to normal, though. I changed the color to see if the style for api 21 was being used and it was, the button text color changed to black on api 21. I know the default theme sets textAllCaps as true for buttons because google thought it would be super-duper-cool, but shouldn't it prioritize my style?
Edit: neverming, I forgot to write "android:" on the style.
I had the same issue and this is what worked for me:
<style name="Theme.CustomTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textAppearanceButton">#style/CustomTheme.ButtonTextAppearance</item>
</style>
<style name="CustomTheme.ButtonTextAppearance" parent="#style/Base.TextAppearance.AppCompat.Button">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
Hope this helps.
In styles.xml
Include the button style in your AppTheme(Which will be using in Application or Activity)
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:buttonStyle">#style/MyButton</item>
</style>
create button style
<style name="MyButton" parent="Widget.AppCompat.Button">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
If you found any issue please let me know.
Make sure that the following line does not say "android:" before "textAllCaps"
<item name="textAllCaps" tools:targetApi="ice_cream_sandwich">false</item>
Your style on values-v21 folder its correct
<style name="ButtonStyle" parent="ButtonStyleBase">
<item name="textAllCaps">false</item>
<item name="android:textColor">#000000</item>
</style>
but same time Api level above 21 your style paste on values-v19 and also style folder xml