Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set specific color to ColorStateList programmatically

I created StateListDrawable from my question Add Color "#e3bb87" to StateListDrawable programmatically , but TextView.setTextColor does not take StateListDrawable (strange it works in layout) but ColorStateList . I read this change statelistdrawable text color android button

In the constructor of ColorStateList, it only accepts arrays of 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});

The color is not defined in colors.xml because I download this color attribute. How can I define like this ?

ColorStateList colorStateList = new ColorStateList(
            new int[][]{
                    new int[]{R.attr.state_pressed}
            },
            **getThisColor**("#e3bb87"));
like image 284
Raymond Chenon Avatar asked Mar 13 '13 11:03

Raymond Chenon


1 Answers

Use this

ColorStateList colorStateList = new ColorStateList(
            new int[][] { new int[] { R.dimen.padding_large } },
            new int[] {Color.parseColor("#e3bb87")});
like image 161
AnujMathur_07 Avatar answered Sep 22 '22 02:09

AnujMathur_07