I had been trying to disable the highlight in a ExpandableListView. I tried setting the next drawable as background, but this didn't work.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/_GREY_Weak"/>
<item android:drawable="#color/_GREY_Weak"
android:state_pressed="true" />
<item android:drawable="#color/_GREY_Weak"
android:state_selected="true" />
<item android:drawable="#color/_GREY_Weak"
android:state_focused="true" />
<item android:drawable="#color/_GREY_Weak"
android:state_checked="true" />
<item android:drawable="#color/_GREY_Weak"
android:state_long_pressable="true" />
<item android:drawable="#color/_GREY_Weak"
android:state_hovered="true" />
<item android:drawable="#color/_GREY_Weak"
android:state_expanded="true" />
</selector>
I tried setting each state drawable as that color, #null or transparent, but still the same. Here are some screenshots of my issue. I want to get rid of that highlight in the childrens as in the parent.
I also triead setting the property drawingCacheHint in the ExpandableListView xml with no luck.
Try adding
android:listSelector="#android:color/transparent"
in ExpandableListView xml
Or override the ExpandableListView style.
Related
I am creating a application that has couple of edittext's that chang color when the edittext has focus or not. When the view has the focus the color should be blue, when normal it should have white color, something like this:
I've tried creating two nine patches and setting the background according to this xml but seems its not working. Can anyone tell me how can I achieve this ?
Xml selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_focused="true"
android:drawable="#drawable/spelling_blue" />
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/spelling_white" />
<item android:drawable="#drawable/spelling_white" />
</selector>
Thanks
I don't think you need to use android:state_window_focused.
Try 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="#drawable/spelling_blue" /> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="#drawable/spelling_blue" /> <!-- focused -->
<item
android:drawable="#drawable/spelling_white" /> <!-- default -->
</selector>
So I'm trying to set a custom ExpandableListView indicator icon but it isn't working. I created an icon and saved it to drawable folder. Here are the icons:
This is the selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/arrow_up" android:state_empty="true"/>
<item android:drawable="#drawable/arrow_down" android:state_activated="true"/>
</selector>
ExpandableListView xml:
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:groupIndicator="#drawable/custom_arrow" />
However, when I launch the app, there is not indicator at all. Any idea what I have done wrong?
this should do the trick
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_expanded="true" android:drawable="#drawable/arrow_up" />
<item android:drawable="#drawable/arrow_down" />
</selector>
you wanted the state_expanded for when the row gets expanded and then any other state besides expanded is just the normal down arrow. You should however handle the state_empty when there is nothing to expand to
I think you just need to add this one line to your selector and change the arrow down condition:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/arrow_up" android:state_empty="true"/>
<item android:drawable="#drawable/arrow_down" android:state_expanded="true"/>
<item android:drawable="#drawable/arrow_up" />
</selector>
I have a problem with a TableRow, which I add dynamically.
private void addRow(String body) {
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TableRow row = (TableRow) inflater.inflate(R.layout.customrow,null);
TextView name = (TextView) row.findViewById(R.id.customName);
name.setText(body);
row.setOnLongClickListener(this);
}
I would like this row to change color upon onClick and onLongClick.
Code in the customrow.xml file is:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableRow1"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_vertical"
android:onClick="showOnClick">
<TextView android:id="#+id/customName"
android:textSize="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_weight="5">
</TextView>
</TableRow>
I have tried to use android:background="#drawable/clickedbackground"with the row but it is not working.
Code in the clickedbackground.xml file is:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:state_focused="false"
android:state_pressed="false" android:drawable="#android:color/transparent" />
<item android:state_selected="false" android:state_focused="false"
android:state_pressed="false" android:drawable="#android:color/transparent" />
<item android:state_pressed="true" android:drawable="#color/custom" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="#color/custom" />
</selector>
Anyone knows what I am doing wrong (color/custom is defined in another xml which works)?
Thank you
You are creating object for tablerow named row. and you have also clickedbackground.xml file. just use below code in addRow method.
row.setBackgroundResource(R.drawable.clickedbackground);
I think it solves your problem.
In your addRow() method you're inflating the row but you're not adding it to any parent layout, and as row is a local variable I think you're not doing it anywhere else, is it a copy/paste problem?
Again, your customrow.xml might be not working because the opening TableRow tag lacks the closing >, but it might be copy/paste problem.
Using android:background="#drawable/bg" with bg being a selector is a common pattern and it should work. You might want to simplify your selector: you don't need to specify all the states for each item and all the combinations. It works with a "first match", so this will do the job:
<?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/custom" />
<item android:state_selected="true" android:drawable="#android:color/transparent" />
<item android:state_focused="true" android:drawable="#color/custom" />
<item android:drawable="#android:color/transparent" />
</selector>
Also, notice that selected and focused are two different states, focused being the one you get when moving around with dpad.
If this didn't help please specify what "is not working" means: what do you expect? what's happening instead?
Adding
<resources>
<style name="row" parent="#android:style/Widget.Button">
<item name="android:background">#drawable/rows</item>
</style>
</resources>
in styles.xml and setting
style="#style/row"
in the TableRow did the job.
where the rows.xml in the drawable is
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="#color/blue" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="#color/custom" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="#color/white" />
<item
android:state_enabled="true"
android:drawable="#android:color/transparent" />
</selector>
do not forget to add to the style
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
Otherwise, you will not be able to use the states of a rowLayout.
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 there a way to highlight an ImageButton when it's pressed?
You can define a drawable via XML and use the selector, like below, to use different (i.e. highlighted) images for different button states:
i.e. res/drawable/button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bg_catlocfilter" android:state_pressed="false" />
<item android:drawable="#drawable/bg_catlocfilter_dark" android:state_pressed="true" />
<item android:drawable="#drawable/bg_catlocfilter" android:state_focused="false" />
<item android:drawable="#drawable/bg_catlocfilter_dark" android:state_focused="true" />
</selector>
Use this resource then for the ImageButton view.