2013-03-13 53 views
3

我创建StateListDrawable从我的问题Add Color "#e3bb87" to StateListDrawable programmatically,但TextView.setTextColor不采取StateListDrawable(奇怪它工作在布局),但ColorStateList。我读这change statelistdrawable text color android button设置特定的颜色来ColorStateList编程

在ColorStateList的构造函数,它只接受,因为我下载这个颜色属性不是colors.xml定义的INT

ColorStateList colorStateList = new ColorStateList(
      new int[][]{ 
        new int[]{R.attr.state_pressed}, 
        new int[]{R.attr.state_selected}, 
        new int[]{-R.attr.state_selected}, 
      }, 
      new int[]{ 
        Color.GREEN, 
        Color.BLUE, 
        Color.RED}); 

颜色阵列。我怎样才能定义这样的?

ColorStateList colorStateList = new ColorStateList(
      new int[][]{ 
        new int[]{R.attr.state_pressed} 
      }, 
      **getThisColor**("#e3bb87")); 

回答

6

使用此

ColorStateList colorStateList = new ColorStateList(
      new int[][] { new int[] { R.dimen.padding_large } }, 
      new int[] {Color.parseColor("#e3bb87")}); 
+0

我goinf张贴此。 – 2013-03-13 11:53:27

+0

幸好我是第一个。 :D :) – 2013-03-13 12:11:40

相关问题