i am trying to modify the underline color of a EditText by applying a theme.
Style:
<style name="MyTheme.EditText" parent="Widget.AppCompat.EditText">
<item name="colorControlActivated">#color/green</item>
</style>
EditText:
<EditText
android:id="#+id/editText_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_enter_amount"
android:theme="#style/MyTheme.EditText"/>
Basically it works, but when i try to select or move the cursor the selection handle is also underlined. You can see this in the screenshot.
Does someone know how to fix this?
You can use this style as a
<EditText
style="#style/MyTheme.EditText"/>
Or, you can separate your theme for referencing the editTextStyle attribute.
<style name="MyEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="colorControlActivated">#color/green</item>
</style>
<style name="MyTheme.EditText">
<item name="editTextStyle">#style/MyEditTextStyle</item>
</style>
<EditText
android:theme="#style/MyTheme.EditText"/>
Alright, but where are these underlines come from?
android:theme is an attribute of View and when you set a style as android:theme, that style will be wrapped by ContextThemeWrapper with context theme while in inflation of view.
So that means, if you set android:theme property with style that contains android:background item like
<item name="android:background">#color/green</item>
every child view of this theme owner will be have a green background.
"Widget.AppCompat.EditText" is a style and references ?attr/editTextBackground as a "android:background". And in v21/values-21.xml file #drawable/abc_edit_text_material is defined as editTextBackground.
So, for your example, #drawable/abc_edit_text_material becomes a background of your EditText and SelectionHandlers.
You should remove parent attribute. This is caused only API 23 device.
<style name="MyTheme.EditText">
<item name="colorControlActivated">#color/green</item>
</style>
I had the same issue.
My layout shows a Edittext inside a blue box. There i wanted to have a white text and a white underline and a white selection control.
I've set all in my AppTheme. All fine!
But i also had a Recyclerview blow the blue box. The RecyclerView has white cards that contains Edittext. White text, underline and control makes no sense in white cards. :)
So i tried to change the color of the text, underline and controls to dark gray. But with no success. I had the same issues with the control like in this question.
I tried using the solved answer, but this didn't helped me.
Maybe my fault, don't know.
So i post here my solution, even the question already answered.
Inside the styles.xml i added:
<style name="RecyclerEditText">
<item name="colorAccent">#color/darkGray</item>
<item name="colorControlNormal">#color/darkGray</item>
<item name="colorControlActivated">#color/darkGray</item>
</style>
and in the layout xml i added inside edittext:
android:textColor="#color/darkGray"
android:textColorHint="#color/darkGray"
android:theme="#style/RecyclerEditText"
--
Now i have no offset in control icon, and no double underline.
Thanks a lot #litmon !
You pushed me to the "remove parent" idea.
Related
I have the following in my styles.xml
<style name="dialog_style" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#ffaaaa00</item>
<item name="android:background">#ff444400</item>
<item name="android:textColorPrimary">#ffa25600</item>
</style>
(The horrible colours are for testing only!)
This gives the following
What I want is a dark/black background but when I do that, the text is unreadable.
Q: How do I change the text colour of "Cut", "Copy"...?
tia,
Kevin
I think it's a little bit better solution than user3247782's,
<style name="CustomAlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
...
<item name="android:popupBackground">#android:color/transparent</item>
</style>
You can change them by following style names:
<item name="colorAccent">#color/twoCuteSelectionHandlersColor</item>
<item name="android:textColorHighlight">#color/selectionColor</item>
Also you can set highlight color directly for pacific EditText using android:textColorHighlight attribute in xml layout or programmatically:
et.setHighlightColor(color);
For context menu you need create your own context menu. check this question for how disabling default context menu and implementing custom menu.
This isn't really an answer. The black-on-black edit menu is only generated from an EditText contained in an AlertDialog. The same code in a Fragment gives black-on-white.
So I "solved" my problem by converting the AlertDialog into a Fragment.
The original question, though, is still unanswered.
Alert Dialog and Popup Menu generaly take the color of #ColorAccent as the background. So try changing the colorAccent or just inflate a custom xml with the specifications you want.
Just change the parent of it from Theme.Material.Light to Theme.Material .
It will make the text white, there.
I fixed it by setting a background color with opacity in the style of the alertdialog
In styles.xml
<style name="AppCompatAlertDialogStyle">
...
<item name="android:background">#color/black_overlay</item>
...
</style>
In colors.xml
<color name="black_overlay">#66000000</color>
If you use MaterialAlertDialogBuilder then you can define background color through colorSurface attribute.
Then in styles you can just set background to transparent.
android:background="#android:color/transparent"
Dialog will use the one define in colorSurface and "copy/paste" will use default system colors (e.g. white).
So I am trying to change my app color to blue and some of most the views I have are not willing to cooperate with me.
Here is the image:
Here I want to change the color of the green parts on the spinner, edittext and checkbox views (which are green) to black or blue.
I've looked all over Stack Overflow and I can't find the solution!
Thank you very much, If possible I would like to have a XML solution but I wouldn't mind a programmatic solution!
Add these to your base theme in styles.xml
<item name="colorControlNormal">#color/YOUR_COLOR</item>
<item name="colorControlActivated">#color/YOUR_COLOR</item>
<item name="colorControlHighlight">#color/YOUR_COLOR</item>
Note: The above change will affect the EditTexts and other views probably throughout the application.
If not, and if you are using the AppCompat v22 support library, you can specify the theme in the EditText like: android:theme="#style/Theme.App.Base.
This will ensure the style won't also affect other views in your layouts that you don't want to change
Also if you want to change the above solution, just add another Theme specific to EditTexts and Spinners and apply it to all Spinners if you want
<style name="MyWidgetTheme">
<item name="colorControlNormal">#color/YOUR_COLOR</item>
<item name="colorControlActivated">#color/YOUR_COLOR</item>
<item name="colorControlHighlight">#color/YOUR_COLOR</item>
</style>
and in your EditText, Spinner or any other View, just assign this theme:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Demo"
android:lines="1"
android:theme="#style/MyWidgetTheme"
/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="#style/MyWidgetTheme"></Spinner>
Take a look to this resource generator.
Choose your color, the widgets you want to generate and voila! You copy them to your project and reference them in your xmls.
I have a custom theme created with this generator. It has a custom style for Spinners which I don't like. I want to change the background drawable but I can't seem to figure out which property controls this.
This is what the themed version looks like
And here is what it will look like when using the Holo.Light theme.
Notice the dark gray lines around the dropdown list in the first (themed) image. This is what I want to get rid of. What property controls this? I want them to match the default.
Also, what controls the vertical aligment of the dropdown list? As you can see, it is overlapping with the Spinner in the first image (the line under it isn't visible as it is in the second image).
The attribute you want is android:popupBackground on the Spinner element.
If you look closely, the holo popup also overlaps the spinner some, but there is a bunch of padding for the drop shadow, so it looks good.
However, you can use android:dropDownVerticalOffset on the Spinner element to adjust it.
We came across the same issue. It has to do with the Android Holo theme generator.
Here are the lines that you should remove from your Theme.xml file...
<item name="android:spinnerStyle">#style/SpinnerCustom</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemCustom</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Custom</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Custom</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Custom</item>
...by removing these, we now have the standard Holo.Light theme on the spinner dropdowns.
You need to change the parent of spinnertheme to android:Widget.Holo.Light.Spinner
<style name="SpinnerTHEME" parent="android:Widget.Holo.Light.Spinner">
<style name="spinner_style" parent="android:Widget.Holo.Light.Spinner">
<item name="android:paddingLeft">#dimen/ten_dp</item>
<item name="android:paddingRight">#dimen/ten_dp</item>
</style>
I have a dialog box that I create to display messages in android. It basically contains a text view in a scrollview like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/about_msg"
android:text="#string/about_msg"
android:autoLink="web"
android:padding="10dip"
style="#style/DialogTextSmall" />
</ScrollView>
As you can see I have applied a style to TextView the style looks like this
<style name="DialogTextSmall">
<item name="android:textSize">#dimen/text_size_small</item>
</style>
The application theme set is like this
<style name="AppTheme" parent="android:Theme.Light">
The Problem:
On ICS api-15 it shows fine black text on white background of TextView.
The problem is When I show dialogbox in Froyo its the text does'nt seem to show even though it seems to have taken space - My guess is the color of text is same as background (greyish black)
I know I can quick fix by hard-coding black background and white text, but Is it not possible to have the default colors of platform for the text color and background of the TextView to appear, without me having to hardcode them ?
You can inherit a parent style and then only change the values you want to change. Try changing your XML to this:
<style name="DialogTextSmall" parent="#android:style/Widget.TextView>
<item name="android:textSize">#dimen/text_size_small</item>
</style>
The list of styles you can inherit can be found in the AOSP source on Github here.
EIDT:
By default text views have black text and transparent background, so you will need to set one or the other if the background behind the text view (which, again, is transparent) is black.
Inheritance from Textview style did not really help. It is a little quirky problem and here is one way to do it
http://blog.andromo.com/2011/fixing-text-colours-on-an-alertdialog-when-using-theme-light/
In my case I did it another way
Solved it for theme I inherited it from default android theme
<style name="Theme" parent="android:Theme"></style>
<style name="Theme.AppTheme" parent="#android:style/Theme.Light"/>
and
<style name="DialogTextSmall">
<item name="android:textSize">#dimen/text_size_small</item>
<item name="android:textColor">#android:color/white</item>
</style>
This way for all platforms , froyo, gingerbread and above, the dialog boxes are black and text is white on them
I styled my App using a theme as described here.
<style name="MyThemeNameHere" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:textColor">#eee</item>
<style>
It works like a charm in most of the App. The background is pretty dark while the text color is bright and text looks good and is easy to read.
Now in the search dialog that android creates for me the background is white, but the text color picks up my style and gets very bright and thus extremely hard to read. I tried also setting android:background to a dark color - This fixed the problem in the search dialog, but caused all textview, etc to get a dark background rather than transparent.
I want to either set the the color or the background only on the search dialog. How do I do this?
As pointed out by Mark Philip the solution can be found in this question:
Android Styling/Theming of just Search Dialog
Basically it should be styled like so
<style name="master" paret="#android:style/Theme.NoTitleBar">
<item name="android:textColorPrimary">#EEEEEE</item>
<item name="android:textColorSecondary">#EEEEEE</item>
<item name="android:textColorTertiary">#EEEEEE</item>
</style>
The root cause was that I styled the android:textColor which should never be styled.