Add Color "#e3bb87" to StateListDrawable programmaticallyという質問から StateListDrawable を作成しましたが、 TextView.setTextColor は StateListDrawable (レイアウトで機能するのは奇妙です) ではなく、 ColorStateList を使用します。この変更statelistdrawable text color android buttonを読みました
ColorStateList のコンストラクターでは、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});
この色属性をダウンロードしたため、colors.xml で色が定義されていません。どうすればこのように定義できますか?
ColorStateList colorStateList = new ColorStateList(
new int[][]{
new int[]{R.attr.state_pressed}
},
**getThisColor**("#e3bb87"));