Change EditText UI In Android - android

I want to change all EditText UI In android. For example I want to change On Focus, On Blur and ... style. How can I do it? Actually I read some snippet, but I don't understand what they do!

1- create selector for different state
<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>
2- To apply the customize drawable xml use the android:backgroung attibute of the EditText
android:background="#drawable/yourXml"
http://www.androidworks.com/changing-the-android-edittext-ui-widget

If you want to change the looks of EditText when certain events like onFocus, onPressed too place, then you will need Selector.
Selector is a drawable and is implemented as xml file, the elements in selector files will refer to specific state. Each Element maps to a specific state.
To change the look and feel of UI components, you can use background, src attributes,etc.
and this link is just the one thats needed.
http://developer.android.com/guide/topics/ui/themes.html

Related

my android spinner doesn't look fine

I need to customize my android spinner. For this I created this spinner_selector.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/spinner_default" />
<item
android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/spinner_default" />
<item
android:state_pressed="true"
android:drawable="#drawable/spinner_pressed" />
<item
android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/spinner_focused" />
<item
android:state_enabled="true"
android:drawable="#drawable/spinner_default" />
<item
android:state_focused="true"
android:drawable="#drawable/spinner_focused" />
<item
android:drawable="#drawable/spinner_default" />
</selector>
and then set the background of spinner : android:background="#drawable/spinner_selector"
The problem is that the spinner looks really horrible. Before :
After :
and when it is pressed, it looks like this :
The image that I use is this :
How to solve this? I have this problem for Spinner, Button and EditText too. I really need to customize these components. Please help. Any idea is welcome.
To align text to right a bit, you can use padding in your XML please give Padding to the Spinner like this for ex: android:padding=5dp
The problem seems is the height and width of the Spinner, your need to change it,
either you can give any static value or use wrap content with setting image size bigger.

Use selector file to get rid of orange-focus button hilite?

I took the btn_default.xml file from the android sdk under platforms/android-7/data/res/drawable-mdpi and stuck in my application's drawable directory.
Then, I took all the 9-patch images referenced in the XML file and copied those to my drawable directory also.
Next, I modified each 9-patch image having any orange in it so it was red (for testing) and saved it.
When I run my app, and focus a button with the keypad, or just touch one, I'm still getting the orange hilite color around the button. Where is that orange hilite coming from???
This is my selector file:
<?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="#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>
Well, after much digging around, I found the answer below. It doesn't seem possible to set the selector color (btn_square_overlay_pressed.png) from a selector file. I had to setSelector() on my gridview object which was populating it's contents from an ImageAdapter which was getting it's images from the xml selector file.
How to change the fading orange color In ExpandableListView?

How to reference the system select button image for custom preference in Android

I have a customer preference widget (xml) which basically contains a TextView and next to that a right aligned ImageButton.
What I am trying to do is set the image for my image button to whatever is used as default by the preferences system. For example see the attached image where I've highlighted the type of image I want to use.
I've tried looking online and saving the ic_btn_round image into my drawables and using that, but it just doesn't look right.
Any advice welcome, thank you
This circle button comes from DialogPreference. If we look into how this preference is implemented, we'll find, that it uses widget described in this xml file:
<!-- Layout used by DialogPreference widgets. This is inflated inside
android.R.layout.preference. -->
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dip"
android:layout_gravity="center_vertical"
android:background="#drawable/btn_circle"
android:src="#drawable/ic_btn_round_more" />
So you need to look into 2 more files: drawable/btn_circle and drawable/ic_btn_round_more.
btn_cicle.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/btn_circle_normal" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/btn_circle_disable" />
<item android:state_pressed="true" android:state_enabled="false"
android:drawable="#drawable/btn_circle_disable" />
<item android:state_pressed="true"
android:drawable="#drawable/btn_circle_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/btn_circle_selected" />
<item android:state_enabled="true"
android:drawable="#drawable/btn_circle_normal" />
<item android:state_focused="true"
android:drawable="#drawable/btn_circle_disable_focused" />
<item
android:drawable="#drawable/btn_circle_disable" />
</selector>
ic_btn_round_more.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:drawable="#drawable/ic_btn_round_more_disabled" />
<item
android:drawable="#drawable/ic_btn_round_more_normal" />
</selector>
All drawables referenced from these two xml files are actual *.png files.
So basically you need to use two images to achieve desired effect. But all these resources are internal to Android, and you can't use them directly. The easiest way is to just copy them to your project (as you did with ic_btn_round ).

Android ImageButton state not changing

I have an issue with my ImageButton not changing state. When I click, or rather touch, the button it stays as the same image. Here is the XML I am using as a selector.
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="#drawable/pushed" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="#drawable/pushed" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="#drawable/pushed" />
<item
android:drawable="#drawable/default" />
</selector>
I call this selector from my main.xml as
android:background="#drawable/imagechoice"
imagechoice.xml is the file with the selector
I don't understand why this is not working, unless I have to have some java code, but everything I've seen said this should work.
When using an ImageButton, isn't it the 'src' property you should use and not background?
Make sure that you copy the same images and the button XML into every "drawable" folders (hdpi,ldpi,mdpi).
That's how I solved this problem on my app.
Good luck :)
I have nearly the same XML and it works just fine. Are you sure you're not replacing the drawable in code somewhere?
On another note, your XML can be simplified by using the cascading nature of the state matching.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/pushed"
/>
<item android:state_focused="true"
android:drawable="#drawable/pushed"
/>
<item android:drawable="#drawable/default"
/>
</selector>
This is my xml of a button with my own custom image on it and it works great:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="#drawable/btn_off" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="#drawable/btn_pressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/btn_pressed" />
<item android:drawable="#drawable/btn_off" />
</selector>
Make sure you set Image button background as mentioned below.I think you are not setting the selector as background instead you are setting the image as background.
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_up_selector"
android:text="1"
android:textColor="#fffafa"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"/>

Is it possible to change the radio button icon in an android radio button group

I am wanting to allow the user of my android application the ability to set some parameters. The radio button is ideal for this situation. However, I don't like the radio buttons are rendered.
Is it possible to change the radio button icon? For example, is it possible to create a custom layout for each row and in that layout reference my own icon and change the font et al.
Yes that's possible you have to define your own style for radio buttons, at res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="android:Theme">
<item name="android:radioButtonStyle">#style/RadioButton</item>
</style>
<style name="RadioButton" parent="#android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">#drawable/radio</item>
</style>
</resources>
'radio' here should be a stateful drawable, radio.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="#drawable/radio_hover" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="#drawable/radio_normal" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="#drawable/radio_active" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="#drawable/radio_active" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="#drawable/radio_hover" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="#drawable/radio_normal_off" />
<item android:state_checked="false" android:drawable="#drawable/radio_normal" />
<item android:state_checked="true" android:drawable="#drawable/radio_hover" />
</selector>
Then just apply the Custom theme either to whole app or to activities of your choice.
For more info about themes and styles look at http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/ that is good guide.
You can put custom image in radiobutton like normal button.
for that create one XML file in drawable folder
e.g
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/sub_screens_aus_hl"
android:state_pressed="true"/>
<item android:drawable="#drawable/sub_screens_aus"
android:state_checked="true"/>
<item android:drawable="#drawable/sub_screens_aus"
android:state_focused="true" />
<item android:drawable="#drawable/sub_screens_aus_dis" />
</selector>
Here you can use 3 different images for radiobutton
and use this file to RadioButton like:
android:button="#drawable/aus"
android:layout_height="120dp"
android:layout_width="wrap_content"
The easier way to only change the radio button is simply set selector for drawable right
<RadioButton
...
android:button="#null"
android:checked="false"
android:drawableRight="#drawable/radio_button_selector" />
And the selector is:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_checkbox_checked" android:state_checked="true" />
<item android:drawable="#drawable/ic_checkbox_unchecked" android:state_checked="false" /></selector>
That's all
yes....`
from Xml
android:button="#drawable/yourdrawable"
and from Java
myRadioButton.setButtonDrawable(resourceId or Drawable);
`
Here's probably a quick approach,
With two icons shown above, you shall have a RadioGroup something like this
change the RadioGroup's orientation to horizontal
for each RadioButton's Properties, try giving the icon for Button
under CompoundButton,
adjust the Padding and size,
and set the Background attribute when checked.
In case you want to do it programmatically,
checkBoxOrRadioButton.setButtonDrawable(null);
checkBoxOrRadioButton.setBackgroundResource(R.drawable.resource_name);

Categories

Resources