代码集中的ColorStateList

时间:2014-07-11 06:16:15

标签: android styles

  1. 我希望代码设置ColorStateLit,checked = true show theme_color 颜色和假显示Color.BLACK,我想使用Methods2设置, 但你无法实现!我们通常在xml中使用颜色资源 式:

    Method1:
    
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="@color/theme_color"/>
    <item android:state_checked="false" android:color="@color/black"/>
    </selector>
    
    Mehtods2:
    
    int[][] states = new int[2][];      
    states[0] = new int[] {};
    states[1] = new int[]{android.R.attr.state_checked};        
    int colors[] = new int[]{Color.BLACK,theme_color};      
    ColorStateList csl = new ColorStateList(states, colors);
    

0 个答案:

没有答案