如何集中时,改变的TableRow的背景颜色?颜色、背景、TableRow

2023-09-04 10:22:47 作者:傻子爱上骗子

我有一个表行,我试过很多事情来改变其颜色,当它集中,但集中时,它永远不会改变颜色。有没有办法做到这一点?我想这也该变了颜色上的点击,但只有当它的聚焦:

  r.setOnTouchListener(新OnTouchListener(){
    公共布尔onTouch(查看为arg0,MotionEvent ARG1){
        如果(arg0.isFocused())
        {
            arg0.setBackgroundColor(Color.BLUE);
            //arg0.isFocused();
        }
        返回false;
}});
 

解决方案

您需要设置行的背景颜色为状态列表绘制(处理选择,pressed,主动,非主动)。

  

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

 < XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <! - 活动状态 - >
    <项目安卓state_selected =真正的机器人:state_focused =假的Andr​​oid版本:STATE_ pressed =假机器人:可绘制=@机器人:彩色/透明/>
<! - 非活动状态 - >
    <项目安卓state_selected =假的Andr​​oid版本:state_focused =假的Andr​​oid版本:STATE_ pressed =假机器人:可绘制=@机器人:彩色/透明/>
     <  - !pressed状态 - >
     <项目的android:STATE_ pressed =真正的机器人:可绘制=@机器人:彩色/黄色/>
    <! - 选中状态(使用D-PAD) - >
     <项目安卓state_focused =真正的机器人:state_selected =真正的机器人:STATE_ pressed =假机器人:可绘制=@机器人:彩色/黄色/>
 < /选择器>
 
如何更改WPS文档的背景颜色

尝试这些链接也为乌拉圭回合的问题

http://www.gersic.com/blog.php?id=56

http://developer.android.com/guide/topics/ui/themes.html

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