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.
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?
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..!
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
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 am struggling with this which apparently is a very simple effect but incredibly haven't found any intutitive way for doing it in Android.
I have a ListView and I managed to customize the background images so the selected item gets highlighted by getting a new background drawable. This I do creating a new style where I set the android:listSelector attribute to point a StateListDrawable where I have specified which drawables to use for every state.
However each ListView item is a LinearLayout where i have two TextViews. My goal is to be able to change the text color of these child views whenever the parent is selected or pressed, at the same time as the background drawable does. I know there is a ColorStateList but haven't been succesful setting that up.
Has anybody succeed getting something like this to work?
Thanks.
Neither of these are possible answers when your ListView is compromised of a layout that has multiple views. You need to set your child views to:
android:duplicateParentState="true"
Now you can use the methods others have described above to declare your TextViews' colors using a selector such as:
android:textColor="#drawable/my_row_selector"
and I'm sure you're aware, but the selector can be as simple as:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#color/white" />
<item android:color="#color/black" />
</selector>
As you can see, #color values are allowed. Hope this helps.
Also - android:state_pressed is used in conjunction with the AdapterView.OnItemClickListener.
in your textview propeties
android:textColor="#color/text_selector"
in res/color
text_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="YOUR_CUSTOM_COLOR" />
<item android:state_selected="true" android:color="YOUR_CUSTOM_COLOR" />
<item android:color="YOUR_CUSTOM_COLOR" />
</selector>
In order to make it work on selection use the following code:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#fff"/>
<item android:state_activated="true" android:color="#fff"/>
<item android:color="#000" />
</selector>
Apparently the key is state_activated="true" state.
When you are deploying the app for Android 11+ (HoneyComb+), you should use
android:state_activated="true"
for selected list state.
For the earlier versions use the combination of:
android:state_checked="true"
android:state_activated="true"
Of course don't forget to include the
android:duplicateParentState="true"
so the view can get the activated/checked state from a parent list view item
Also you may create a res/color folder and add a file "text_selector.xml" with the following lines:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:color="#f0f"/>
<item android:state_pressed="true" android:color="#f0f"/>
<item android:color="#000"/>
</selector>
After that assign in TextView:
android:textColor="#color/text_selector"