[英]change background of textview for listview item get focused
i have this listview 我有这个列表视图
each listview item has a textview that have background , i want to change the background of the textview of listview item get focused . 每个listview项都有一个具有背景的textview,我想改变listview项的textview的背景。
You should use Selector . 您应该使用Selector 。
Edit: Use selector drawable as a background for ListView elements, or specify a android:listSelector for a ListView 编辑:使用选择器drawable作为ListView元素的背景,或为ListView指定android:listSelector
you have change background color in onfocusChangeListener. 您已经在onfocusChangeListener中更改了背景颜色。 Try with following code, 尝试以下代码,
livView.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
TextView tv=(TextView)v.findViewById(R.id.yourId);
if(hasFocus){
tv.setBackgroundColor(bg_color);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.