如何集中时,改变的TableRow的背景颜色? [英] How to change the background color of a TableRow when focused?
问题描述
我有一个表行,我试过很多事情来改变其颜色,当它集中,但集中时,它永远不会改变颜色。有没有办法做到这一点?我想这也该变了颜色上的点击,但只有当它的聚焦:
r.setOnTouchListener(新OnTouchListener(){
公共布尔onTouch(查看为arg0,MotionEvent ARG1){
如果(arg0.isFocused())
{
arg0.setBackgroundColor(Color.BLUE);
//arg0.isFocused();
}
返回false;
}});
您需要设置行的背景颜色为状态列表绘制(处理选择,pressed,主动,非主动)。
<一个href="http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList">http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT;选择的xmlns:机器人=http://schemas.android.com/apk/res/android&GT;
&LT;! - 活动状态 - &GT;
&LT;项目安卓state_selected =真正的机器人:state_focused =假的Android版本:STATE_ pressed =假机器人:可绘制=@机器人:彩色/透明/&GT;
&LT;! - 非活动状态 - &GT;
&LT;项目安卓state_selected =假的Android版本:state_focused =假的Android版本:STATE_ pressed =假机器人:可绘制=@机器人:彩色/透明/&GT;
&LT; - !pressed状态 - &GT;
&LT;项目的android:STATE_ pressed =真正的机器人:可绘制=@机器人:彩色/黄色/&GT;
&LT;! - 选中状态(使用D-PAD) - &GT;
&LT;项目安卓state_focused =真正的机器人:state_selected =真正的机器人:STATE_ pressed =假机器人:可绘制=@机器人:彩色/黄色/&GT;
&LT; /选择器&GT;
尝试这些链接也为乌拉圭回合的问题
http://www.gersic.com/blog.php?id=56
I have a table row and I tried many things to change its color when it's focused, but it never changes color when focused. Is there any way to do this? I tried this also which changed color on click but only when its' focused:
r.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
if(arg0.isFocused())
{
arg0.setBackgroundColor(Color.BLUE);
//arg0.isFocused();
}
return false;
}});
You need to set the background color of your row to a state list drawable (that handles select, pressed, active, non-active).
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active state -->
<item android:state_selected="true" android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
<!-- Inactive state-->
<item android:state_selected="false" android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
<!-- Pressed state-->
<item android:state_pressed="true" android:drawable="@android:color/yellow" />
<!-- Selected state (using d-pad) -->
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@android:color/yellow" />
</selector>
try these links too, for ur problem
http://www.gersic.com/blog.php?id=56
http://developer.android.com/guide/topics/ui/themes.html
这篇关于如何集中时,改变的TableRow的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!