How to change the background color of a TableRow when focused?

前端 未结 3 1344
情话喂你
情话喂你 2020-12-18 14:28

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 wh

相关标签:
3条回答
  • 2020-12-18 14:55

    Check the solution

    0 讨论(0)
  • 2020-12-18 14:59

    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

    0 讨论(0)
  • 2020-12-18 15:09

    To everyone with the "resource not found" error for yellow, just make your own yellow:

    Create a file:

     Project
      -> res
        -> values
          - colors.xml
    

    And put this in the file:

     <?xml version="1.0" encoding="utf-8"?>
     <resources>
       <color name="yellow">#FFFF00</color>
     </resources>
    

    Then change the places in XML that reference yellow to read like this:

    android:drawable="@color/yellow"
    
    0 讨论(0)
提交回复
热议问题