您的位置:首页 > 其它

选择后显示不同的颜色和图片的方法

2011-04-14 09:49 302 查看
在drawable中加入如下xml文件:

1、颜色的

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_selected="true" android:color="@drawable/darkblue"/>

<item android:color="@drawable/white"/>

</selector>

2、图片的

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/cameras_on"

android:state_selected="true" />

<item android:drawable="@drawable/cameras_off" />

</selector>

在activity中引用该drawable文件,如下:

camera=tabHost.newTabSpec("ID1").setIndicator("Cameras", this.getResources().getDrawable(R.drawable.cameratab)).setContent(R.id.tab_demo_tv1);

cameraTextView.setTextColor(this.getResources().getColorStateList(R.color.tabtitlecolor));

通过设置select中选择的值来给其赋值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: