I'm trying to set TestView background with GradientDrawable that is set for different states. When using methods: setStroke and setColor (that gets ColorStateList) for a GradientDrawable it seems that the ColorStateList is being ignored. For the following code:
int frameColor = Color.parseColor("#000000");
GradientDrawable charFrameDrawable = new GradientDrawable();
ColorStateList colorStateList = new ColorStateList(new int[][]{{android.R.attr.state_activated}}, new int[]{frameColor});
charFrameDrawable.setStroke(1, colorStateList);
charFrameDrawable.setColor(colorStateList);
textView = new TextView(this);
textView.setBackground(charFrameDrawable);
}
@Override
protected void onStop() {
super.onStop();
int[] arr =textView.getBackground().getState();
for (int i =0; i<arr.length;i++)
{
Log.e("12345",String.valueOf(arr[i]));
}
I'm getting the following output:
2020-07-01 03:21:45.776 29138-29138/com.example.testcheckbox E/12345: 16842910 2020-07-01 03:21:45.776 29138-29138/com.example.testcheckbox E/12345: 16843597
As you can see i'm getting two id's although there is only one state, and the first id belong to state_enabled const (which isn't part of the state i set). Can someone help me with the issue? Thanks