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..!
Related
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?
Im trying to create custom button and i cant see my problem.
i create in res/drawable/ custom.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="#drawable/forwardpress"></item>
<item android:state_focused="true" android:drawable="#drawable/forwardhover"></item>
<item android:drawable="#drawable/forward"></item>
</selector>
and on main.xml i have this button
<Button
android:id="#+id/bFor"
android:background="#drawable/custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right" />
The problem is, button is stay presed without animation, (yes i have 3 diferent picture in drawable folder)
Funny thing is, I for one button works but the other does not
i try this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/backpress" android:state_pressed="true"/>
<item android:drawable="#drawable/back"/>
its work but for second button i try the same process
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/forwardpress" android:state_pressed="true"/>
<item android:drawable="#drawable/forward"/>
</selector>
for second button doesnt work, wierd...
Clean and build your project again.
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.
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/
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>