I get this error message while trying to create custom button, i have already tried most of the answers similar to my question but cant get it working yet. Any help much appreciated. Also, as this is my first time posting here, forgive me if anything wrong with the rules.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
<Selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/touchlighter" android:state_pressed="true"/>
<item android:drawable="#drawable/touch"/>
</Selector>
</RelativeLayout>
You're typing <Selector ... where the attributes of the <RelativeLayout> should go.
I think the right XML should be:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android">
<Selector>
<item android:drawable="#drawable/touchlighter" android:state_pressed="true"/>
<item android:drawable="#drawable/touch"/>
</Selector>
</RelativeLayout>
Related
I am new at Android. I am trying to change the icon of the CheckBox.
Here is my code, where star_checked and start_unchecked are .png file in my drawable.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="=#drawable/star_checked" android:state_checked="true"/>
<item android:drawable="#drawable/star_unchecked" android:state_checked="false" />
</selector>
I am getting the following error:
C:...\app\src\main\res\drawable\selector_priority.xml:3: AAPT: error: '=#drawable/star_checked' is incompatible with attribute drawable (attr) reference.
Any idea of what the issue could be?
Thanks in advance
It's due to syntax error you are using an extra equal sign in android:drawable="=#drawable/star_checked" this line.
Use this code.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="#drawable/star_checked" />
<item android:state_checked="false"
android:drawable="#drawable/star_unchecked" />
</selector>
I am implementing an endless ListView (like in the Facebook app). I want to make item as select(temporarily show background as grey) which I select. when I click on listview, nothing happens(not shown as grey). I tried setting android:focusable="false" and android:cickable="false" for my List view contents. But I didn't notice any chanage What is my fault? Any One help me. Thanks in advance.
You can accomplish this by using a selector which you can set as the background of your list item.
drawable/background_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/gray" android:state_pressed="true" />
<item android:drawable="#color/gray" android:state_selected="true" />
<item android:drawable="#color/gray" android:state_activated="true" />
<item android:drawable="#color/default_color" />
</selector>
layout/list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_list_item"
android:orientation="vertical">
<... />
</LinearLayout>
If you want to show the clicked option as highlighted. Don't put clicklistener to convetview. Use
ListView.SetOnclicklistener(..){
...
}
That is best one to remove the issue.
Try this as background:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/someGreyColor" android:state_activated="true"/>
<item android:drawable="#color/anyColor" android:state_pressed="true"/>
<item android:drawable="#color/backgrounColor"/>
</selector>
I want to make a custom RadioGroup with shapes of my own.
I want the android:checked="true" to look like this:
I think you should use a selector in that case. I use this for CheckBoxes, simply put the resulting XML file as android:background. This whould be an example:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#drawable/radio_checked" />
<item android:state_checked="false" android:drawable="#drawable/radio_unchecked" />
</selector>
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..!
I'm developing a test application for Android, and I'm trying to add a custom image to a button. But when I try to save I get the error "main.xml: Failed to parse file C:\Program Files\Eclipse Workspace\App\res\drawable\custom_button.xml". I don't know how to solve it. I think both main.xml and custom_button.xml are correct.
custom_button.xml:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/button_normal"
android:state_focused="true" />
<item android:drawable="#drawable/button_normal" />
</selector>
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_button"/>
</LinearLayout>
For making this, I followed these two tutorials:
http://developer.android.com/resources/tutorials/views/hello-formstuff.html
And:
http://developer.android.com/reference/android/widget/Button.html
This is not an answer but since I dont have comment perm I will write it here anyways.
Maybe "#drawable/button_pressed" or the other drawable may not be present.
Or like already said in the comment try recreating it. I have had this problem previously. And make sure that if you are copy pasting, not to include any invalid characters.