Remove highlight effect from EditText - android

I want to remove the orange highlight around the EditText. This highlight doesn't match my UI and I really want to get rid of it.
Any ideas?

EditText uses selector for it's background.
From android source code:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/textfield_default" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/textfield_disabled" />
<item android:state_pressed="true" android:drawable="#drawable/textfield_pressed" />
<item android:state_enabled="true" android:state_focused="true" android:drawable="#drawable/textfield_selected" />
<item android:state_enabled="true" android:drawable="#drawable/textfield_default" />
<item android:state_focused="true" android:drawable="#drawable/textfield_disabled_selected" />
<item android:drawable="#drawable/textfield_disabled" />
</selector>
You have to create you own selector where you can use your own drawables for pressed and selected state. You can read more about selectors here

Related

Change all Color on Text Controller

I need change all color for EditText, I tried all my information
ex:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false"
android:state_enabled="true"
android:drawable="#color/colorJust" />
<item
android:state_window_focused="false"
android:state_enabled="false"
android:drawable="#color/colorJust" />
<item
android:state_pressed="true"
android:drawable="#color/colorJust" />
<item
android:state_enabled="true"
android:state_focused="true"
android:drawable="#color/colorJust" />
<item
android:state_enabled="true"
android:drawable="#color/colorJust" />
<item
android:state_focused="true"
android:drawable="#color/colorJust" />
<item
android:drawable="#color/colorJust" />
</selector>
with: android:background="#drawable/edittext_bg"
But result is not good, the pink color is always on top when click and select text
I need to remove this PINK color i hate it!
The colour of the checkboxes, cursor, etc. is determined by your accent see here
Try adding this to your styles:
<item name="android:colorAccent">#color/colorJust</item>
you can choose android:textCursorDrawable="#null", the cursor will use android:textColor color then. or to remove cursor from edittext you can do something like android:cursorVisible="false"

What is structure of a selector to define item

why we define this item in last
<item android:drawable="#drawable/twitter_im_edittext_normal" />
in a selector like this
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:state_enabled="true"
android:drawable="#drawable/twitter_im_edittext_normal" />
<item android:state_window_focused="false"
android:state_enabled="false"
android:drawable="#drawable/twitter_im_edittext_normal" />
<item android:state_pressed="true"
android:drawable="#drawable/twitter_im_edittext_normal" />
<item android:state_enabled="true"
android:state_focused="true"
android:drawable="#drawable/twitter_im_edittext_focused" />
<item android:state_enabled="true"
android:drawable="#drawable/twitter_im_edittext_normal" />
<item android:state_focused="true"
android:drawable="#drawable/twitter_im_edittext_focused" />
<item android:drawable="#drawable/twitter_im_edittext_normal" />
</selector>
See at the official documentation
During each state change, the state list is traversed top to bottom and the first item that matches the current state is used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.
Think of a selector as a switch case. The statement are verified in the order they are listed, so the last one is your default: clause. In case your view doesn't match any of the conditions, it will default to
<item android:drawable="#drawable/twitter_im_edittext_normal" />

Remain Highlighted in Selector.xml

I have the following selector.xml implementation, however, it only highlights when user clicks, however I want to be highlighted until other button clicks. How could I achieve it?
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="#drawable/redo_off" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="#drawable/redo_on" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="#drawable/redo_on" />
<item
android:state_enabled="true"
android:drawable="#drawable/redo_off" />
</selector>
Try defining an item for
android:state_selected="true"
as first item of your selector.
Edit :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="#drawable/redo_on" />
<item
android:state_enabled="false"
android:drawable="#drawable/redo_off" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="#drawable/redo_on" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="#drawable/redo_on" />
<item
android:state_enabled="true"
android:drawable="#drawable/redo_off" />
</selector>
I haven't tried it myself. If it doesn't work take a look at this similar post.

Android Button selector not working properly

I am using the following selector to change the color of a button
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#color/darkgray" />
<item android:state_enabled="true" android:state_pressed="true" android:drawable="#color/background_red_down" />
<item android:drawable="#color/background_red" />
</selector>
I am getting the red color for the button but that's it. I am not getting the gray disabled color, the button is indeed disabled as it is unclickable. I am also not getting the red_down color once I click.
What have I missed?
Thanks
in your color.xml
replace this
<color name="background_red">#9A9484</color>
to
<drawable name="background_red">#9A9484</drawable>
"#9A9484 = your background color"
This is code from my button selector. Modify it's values and it should work for you.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/redtheme_btn_default_normal_holo_light" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/redtheme_btn_default_disabled_holo_light" />
<item android:state_pressed="true"
android:drawable="#drawable/redtheme_btn_default_pressed_holo_light" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/redtheme_btn_default_focused_holo_light" />
<item android:state_enabled="true"
android:drawable="#drawable/redtheme_btn_default_normal_holo_light" />
<item android:state_focused="true"
android:drawable="#drawable/redtheme_btn_default_disabled_focused_holo_light" />
<item
android:drawable="#drawable/redtheme_btn_default_disabled_holo_light" />
</selector>

How to disable the default Button color changing property on onClick

For the default android button, when I click on it, its color is changed to orange for a few seconds (for notifying the user the button is clicked). Anyway, I don't want this property. I don't want to change my button color. How can I disable this property?
Have a look on how button is styled by Android:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/btn_default_normal" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/btn_default_normal_disable" />
<item android:state_pressed="true"
android:drawable="#drawable/btn_default_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/btn_default_selected" />
<item android:state_enabled="true"
android:drawable="#drawable/btn_default_normal" />
<item android:state_focused="true"
android:drawable="#drawable/btn_default_normal_disable_focused" />
<item
android:drawable="#drawable/btn_default_normal_disable" />
</selector>
To style your button with Android's themes images resources, just create your own selector by copying the Android's one and replace all #drawable/btn_default_* by #android:drawable/btn_default_normal in items tag (and just remove items you don't want). For example :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:drawable="#android:drawable/btn_default_normal" />
</selector>
Then, apply this drawable selector as a android:background of your button.
Hope it helps.
(If you want, I can also provide an example of applying this background easily to all your buttons, just ask.)

Categories

Resources