点击事件添加高亮显示

先上代码:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/library_highlight" android:state_pressed="true"/>
    <!-- pressed -->
    <item android:drawable="@drawable/library_highlight" android:state_focused="true"/>
    <!-- focused --> 
    <!-- <item android:drawable="@drawable/button_focused" android:state_hovered="true"/>hovered -->
    <item android:drawable="@drawable/bg_library_selected"/>
    <!-- default -->
</selector>

以点击listview的item高亮显示为例,这个配置文件放在drawable文件夹下。

 

在布局中设置:直接setBackground(xxxid);

代码中设置:

Layout mLayout = findVeiwById(R.id.xxx);
boolean bSelected = true or false;
mLayout.setSelected(bSelected ); 

 

posted on 2013-03-18 11:25  取悦  阅读(502)  评论(0编辑  收藏  举报

导航