setHintTextColor() in EditText(EditText 中的 setHintTextColor())
问题描述
我有一个视图,其中有两个文本框,用户可以从同一屏幕上的另一个视图中选择文本颜色(通过对话框).
I have View in which there are two text boxes, and the user can select text color from another view on the same screen (through dialog box).
因此,当用户通过对话框更改颜色时,我正在更改 EditText 文本及其提示的颜色.但是,当用户选择其他颜色后 EditText 中有一些文本可用时,该文本将以该颜色出现.但是,如果我删除所有这些文本,那么 HintText 的颜色就是以前的颜色.
So when the user changes color via dialog box, I am changing color of EditText text and its hint. But when there is some text is available in EditText after that user selects other color, then that text is coming in that color. But if I remove all that text then the color of HintText is that of the previous color.
例如,当前如果我在文本框中有红色并且用户选择绿色,那么文本是绿色的.但是,如果我删除该文本,那么即使我在代码中更改提示颜色,提示文本也会变为红色.仅当那里有一些文本时才会出现此问题.如果它是空白的并且有提示文本,那么问题就不会出现.
For example, currently if I have red color in text box and the user selects green color so text is there in green color. But if I remove that text then hint text are coming in red even if I change hint color in code. This problem only comes when there is some text there. if it is blank and hint text is there then problem is not coming.
推荐答案
使用它来改变提示颜色.-
Use this to change the hint color. -
editText.setHintTextColor(getResources().getColor(R.color.white));
解决您的问题 -
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,int arg3){
//do something
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
//do something
}
@Override
public void afterTextChanged(Editable arg0) {
if(arg0.toString().length() <= 0) //check if length is equal to zero
tv.setHintTextColor(getResources().getColor(R.color.white));
}
});
这篇关于EditText 中的 setHintTextColor()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EditText 中的 setHintTextColor()
基础教程推荐
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
