开发者

Layout changes are not reflecting in the application

I have created a button widget with custom images by referring this article. I have set images for onclick and onfocus. But I can only see the normal image for the button, nothing changes when I focus or press the butto开发者_运维技巧n.

Here is my code:

custom_button.xml:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_reload_4" />
    <item 
        android:drawable="@drawable/ic_reload_2"
        android:state_pressed="true" />
    <item 
        android:drawable="@drawable/ic_reload_3"
        android:state_focused="true" />
</selector>

Layout:

<Button 
    android:id="@+id/reload_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:background="@drawable/custom_button" />

Images are placed in the drawable folder. I m not sure why its not working. I have also faced issues with the layout,ie I can see the changes in the eclipse when selecting the 'layout' tab but its not shown in the application after updating it. Can anyone help me on this...


Your selector should be like this:

    <?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:drawable="@drawable/ic_reload_2"
        android:state_pressed="true" />
    <item 
        android:drawable="@drawable/ic_reload_3"
        android:state_focused="true" />
 <item android:drawable="@drawable/ic_reload_4" />
</selector>

I.e. you have to place the default item to the end. It seems that android inflates this like a switch-case block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜