form字体和颜色java安卓开发,Android:从.java设置EditText的默认提示颜色

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 use setHint("text") it makes hint color for new created views black.

Also tried setHintTextColor() but the only way it worked for me by setting custom color. Is there a default hint color that I can set by setHintTextColor()?? or maybe some method that does it when it's called?

Code looks like this:

private EditText createNewTextView(String text) {

++x;

final ActionBar.LayoutParams lparams = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);

final EditText editText = new EditText(this);

editText.setLayoutParams(lparams);

editText.setHint("Name" + x);

editText.setHintTextColor(getResources().getColor(R.color.hintcolor));

return editText;

}

p.s. I made new color in colors which is called hintcolor

I've been looking for solution, but there was nothing that would help me, or I just didn't understood it. I'm new at android and programming so don't judge please, just explain. Thanks a lot

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值