2013-03-13 55 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

相關問題