Selector It works on all the buttons at once - android

I have three buttons with
android:background="#drawable/selector_button_dove_gray"
Selector code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_mine_shaft" android:state_pressed="true"/>
<item android:drawable="#drawable/button_dove_gray"/>
</selector>
But background change on all buttons, when i click one of them. What i need do for correctly work?

Related

Custom Android button with selector doesn't load bakground

I have this custom Android button in drawable folder with a selector to load a different image for the clicked buttons
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bt_blue_click" android:state_pressed="true"/>
<item android:drawable="#drawable/bt_blue_unclick"/>
</selector>
Sometimes work fine, others times doesn't show the background of the button.
I have tried also to add the line
<item android:drawable="#drawable/bt_blue_unclick" android:state_pressed="false"/>
(Because the PNG image in background isn't load when the button is unclicked.)
I cannot figure what is the cause of this strange issue.
try this...
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/bt_blue_click" android:state_pressed="true"/>
<item android:drawable="#drawable/bt_blue_unclick"/>
</selector>
its working well in my case..!

android tabwidget custom

i have this custom tab widget..
before i've customized it, by default i have a custom delimiter between each tab..
is there a way to make it still visible although i have a custom backgruond ?
this is my XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/footer_overbg" android:state_pressed="true"/>
<item android:drawable="#drawable/footer_overbg" android:state_focused="true"/>
<item android:drawable="#drawable/footer_overbg" android:state_selected="true"/>
<item android:drawable="#drawable/footer_bg"/>
</selector>
If what i am thinking is correct then you need this
mTabHost.getTabWidget().setDividerDrawable(R.drawable.divider_vertical_dark);
it seems you want a divider between each tab.

Android eclipse add pressed state to ImageView

Is there a way to add a pressed state to an ImageView? I have an image that i place a click listener on, and when I press it I want to change to imageview src for a second to mimic the pressed state of buttons or listview items.
Can I add a selector xml to the src attribute?
Figured it out. You CAN add a selector xml to your src attribute of an ImageView.
In my case, i created "addbuttonbg.xml" in my drawables:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="#drawable/quickaddbutton" />
<item android:state_pressed="true"
android:drawable="#drawable/quickaddbutton_click" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="#drawable/quickaddbutton" />
</selector>
Then set your imageview src to #drawable/addbuttonbg
Yes you can add a selector to get the press effect
Sample:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/postbutton_press" android:state_pressed="true"/>
<item android:drawable="#drawable/postbutton_press" android:state_focused="true"/>
<item android:drawable="#drawable/postbutton_normal"/>
</selector>
To the ImageView's android:src="#drawable/post_btn_click" attribute or android:background="#drawable/post_btn_click" to a button attribute
post_btn_click -> selector drawable's file name

Making a button look pressed in

I'm using Eclipse to write the android application. I've added some standard buttons from the Form Widgets tab and successfully got them opening new windows which display additional buttons.
I would like the button that was pressed, to change appearance and continue to look pressed in after it is selected.
create xml file using the button image like this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#color/transparent" />
<item
android:drawable="#drawable/closebutton" />
</selector>
add the color folder in values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#00000000</color>
</resources>
can use selector
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="#drawable/button_settings" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="#drawable/button_settings" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="#drawable/button_settings_selected" />
<item android:drawable="#drawable/button_settings" />
</selector>
now set this drawable on background property of button in XML, now in coding take a boolean flag when button is pressed set the flag and set the bacground of the button(selected image) and on again click reset flag value and change the imageBackground to the selector again, thats it!!!
Use ImageButton and change the background of the button.
you can use this kind of images depends of you need. Like this https://web.archive.org/web/20160429124711/http://www.devahead.com/blog/2011/08/creating-a-custom-android-button-with-a-resizable-skin/

On click effect on the image button

I have created image buttons instead of normal buttons.On click on the image button I want a click effect as in the normal icon click effect(On click of menu the background of the icon will be yellow color) of android phones.Using the following code I code show an image on click of the image button .What changes I have to make further.
<item android:state_enabled="true"
android:state_pressed="true"
android:drawable="#drawable/production_order" />
android:state_enabled="false"
android:drawable="#drawable/prodution_orders_icon" />
Try this code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="#drawable/camera" />
<item android:state_pressed="false" android:drawable="#drawable/camera" />
<item android:state_pressed="true" android:drawable="#drawable/camera_active" />
</selector>
Instead of using directly ImageButton you can use Button with customized background
Here is the sample tutorial.
create xml file using the button image like this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#color/transparent" />
<item
android:drawable="#drawable/closebutton" />
</selector>
add the color folder in values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="yellow">#ffffff00</color>
</resources>

Categories

Resources