所以我有一个LinearLayout和4个EditText-s,XML中的灰色提示颜色。我有按钮可以动态地将新的EditText-s添加到LinearLayout。问题是当我使用 setHint("text"( 时,它会使新创建的视图的提示颜色变为黑色。
还尝试了setHintTextColor((,但它通过设置自定义颜色对我起作用的唯一方法。是否有可以通过 setHintTextColor(( 设置的默认提示颜色?或者也许是某种在调用时执行此操作的方法?
代码如下所示:
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;
}
附言我用颜色制作了新的颜色,称为提示颜色
我一直在寻找解决方案,但没有什么可以帮助我,或者我只是不明白。我是安卓和编程的新手,所以请不要评判,只是解释一下。多谢
可能为时已晚,但为了其他有同样问题的人,我通过制作一种方法来获取默认的textColorHint来解决它。
它返回当前主题中指定的所有状态(禁用、聚焦、选定...(的提示文本的颜色。
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;
}
我希望这有所帮助。