I'm trying to make underline line color change for EditText (it will be used for input's validation, so it must be able to change in runtime).
I'm using AppCompat library. The problem is that on API 21 and above, I see transparent black line (gray overlay), instead of bolded version.
How to make it the same as in API 16?
I used this code to change tint:
final Drawable originalDrawable = view.getBackground();
final Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable);
DrawableCompat.setTint(wrappedDrawable, Color.RED);
setBackground(view,wrappedDrawable);
Solution found by adding these lines to my theme:
<item name="editTextStyle">#style/Base.V7.Widget.AppCompat.EditText</item>
<item name="editTextBackground">#drawable/abc_edit_text_material</item>
You should not change the background. It's better if you create a theme, and use theme colors (colorPrimary, colorAccent are the most important for widgets) to get the desired effect. Assign the theme to your EditText and enjoy. Note: you should use one of the AppCompat theme as base theme.
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorAccent">#color/accent</item>
</style>
and in your colors.xml
<color name="primary">#ff0000</color>
<color name="accent">#00ff00</color>
Related
I've been trying to change the color of the EditText line on the bottom, but my EditText still doesn't wanna change the color, but it's using the style from Material.
I've tried to change the color following these answer: link
So I have an EditText with the Material form but not the colors I've set.
I've put appcompat-v7 in my Gradle config file, and it's already working for the color primary.
<style name="AppBaseTheme.MiddleTheme.Widget.EditText" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/middle_primary</item>
<!-- Those 3 lines are staying in red war in IntelliJ but it does build the project -->
<item name="android:colorControlNormal">#color/middle_sqool_primary</item>
<item name="android:colorControlActivated">#color/middle_sqool_primary</item>
<item name="android:colorControlHighlight">#color/middle_sqool_primary</item>
</style>
You have to set the colorControlActivated, colorControlHighlight and colorControlNormal in your app theme (or activity theme) not in your edittext style.
Something like this:
<style name="Theme.App.Base" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/middle_sqool_primary</item>
<item name="colorControlActivated">#color/middle_sqool_primary</item>
<item name="colorControlHighlight">#color/middle_sqool_primary</item>
</style>
As a workaround, try using android.support.v7.widget.AppCompatEditText rather than EditText. You should always use that for programmatically created views.
Pretty sure you made it, but be sure you are editing themes in the values folder and not in the values-v21 one (if any).
I had a similar issue. Wanted to change the highlight colour of the menu items. And none of these attributes didn't work (Support Library v25.0.0).
The only attribute that allowed me to change colour on Pre-L devices is this:
<item name="actionBarItemBackground">#drawable/YOUR_DRAWABLE</item>
I stopped searching for further workarounds because it's obvious that Support Library is NOT ready for production code.
Android L uses white background for notifications and grey color for the text on it. But, "#android:style/TextAppearance.StatusBar.EventContent.Title" still sets the color of TextView to same white color like in KitKat or previous versions. It should return the grey color used in new notification style of Android L.
How can I solve it? Thanks in advance.
It seems android-L doesn't override "#android:style/TextAppearance.StatusBar.EventContent.Title", instead introduces new style
<style name="TextAppearance.Material.Notification.Title">
<item name="textColor">#color/primary_text_default_material_light</item>
<item name="textSize">#dimen/notification_title_text_size</item>
</style>
We could make use of both the API based values folders to handle this in proper way.
/values/styles.xml
<style
name="NotificationTitle"
parent="#style/TextAppearance.StatusBar.EventContent.Title" />
/values-21/styles.xml
<style
name="NotificationTitle"
parent="#android:style/TextAppearance.Material.Notification.Title" />
Now call the following line in your TextView
android:textAppearance="#style/NotificationTitle"
Here is what worked for me to resolve this error. In your styles.xml, add the following:
<style name="TextAppearance">
</style>
<style name="TextAppearance.StatusBar">
</style>
<style name="TextAppearance.StatusBar.EventContent">
<item name="android:textColor">#ff6b6b6b</item>
</style>
<style name="TextAppearance.StatusBar.EventContent.Info">
<item name="android:textColor">#ff6b6b6b</item>
</style>
I want to remove an editText default transparency which I saw on android 4.
I already tried to solve the problem with alpha=1 on styles in v11 and v14 folders.
But that's not working.
This is my styles.xml :
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
<item name="android:editTextStyle">#style/MyEditText</item>
</style>
<style name="MyEditText" parent="android:Widget.EditText">
<item name="android:alpha">1.0</item>
</style>
(style for API 14 is the same)
You have to change the background drawable. The reason it is transparent is that the Holo theme's edit text background is based on a 9 patch that has a solid underline, while the rest of the area is transparent.
<style name="MyEditText" parent="android:Widget.EditText">
<item name="android:background">#drawable/my_edit_text_background</item>
</style>
You will need to define your own background drawable, which should probably be a state list drawable so it will look different depending on whether it is in focus.
I'm trying to implement a feature to let the user change the theme.
I've done this but depending on if the theme is light or dark, I need to use the opposite color to draw line on a canvas. I thought the best way to do this would be to simply call R.style.colorAttribute to get the correct color when doing the drawing.
In the styles.xml I have defined the following themes:
<style name="DarkTheme" parent="android:Theme.Holo" />
<style name="LightTheme" parent="android:Theme.Holo.Light" />
Can anyone help on the best way to add an attribute here which will store the color. I've not done this before and was n't sure if I should use the color.xml file or the styles.xml file.
Thanks
And just to make it clear
I for the dark theme I need a white color
and for the light them I need the same attribute but in black.
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional light theme to use your own color like this:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
More about styles on developer.android.com.
I am trying to set custom background colour to title of Theme.Holo.Light application with below xml. But it doesn't work.
Theme.Holo.Light somehow overrides #style/WindowTitleBackground
if I set parent to just android:Theme, it works fine. I want to ave Halo.Light theme but with different background. I have seen custom background layout samples but as I am learning I don't want to go in to that.
Any help appreciated.
Thanks
<style name="theme" parent="android:Theme.Holo.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
<style name="WindowTitleBackground">
<item name="android:background">#000000</item>
</style>
when you use android:background, it must be drawable resource, so using value such as #ff234562 directly will not be valid,in fact you should define the value in colors.xml first,then use like this
<item name="android:background">#color/green</item>
It seems like Android uses bitmaps for that value (either #null or #android:drawable/title_bar).
Try creating a black png and use it instead of the color code:
<style name="WindowTitleBackground">
<item name="android:background">#drawable/black</item>
</style>