Android: Setting EditText's default hint color from .java

后端 未结 1 1538
不知归路
不知归路 2021-01-23 01:57

So I have a LinearLayout and 4 EditText-s in it with grayish hint colors in XML. And I have button that dynamically adds new EditText-s to LinearLayout. The problem is when I us

1条回答
  •  清酒与你
    2021-01-23 02:12

    It may be too late but for the sake of others who have the same problem, I solved it by making a method to get default textColorHint.
    It returns the color of the hint text for all the states (disabled, focussed, selected...) that specified in the current theme.

    int getHintTextColor(Context context) {
        int[] hintTextColor = new int[] { android.R.attr.textColorHint };
        int indexOfAttrTextColorHint = 0;
        TypedArray ta = context.obtainStyledAttributes(hintTextColor);
        int textColor = ta.getColor(indexOfAttrTextColorHint, 0xFF808080);
        ta.recycle();
        return textColor;
    }
    

    I hope this helps.

    0 讨论(0)
提交回复
热议问题