java 如何在android小部件EditText中添加水印?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5962872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 13:42:06  来源:igfitidea点击:

How to add watermark in android widget EditText?

javaandroidandroid-widget

提问by saiket

Please provide the implementation of watermark text in EditText widget of android,even after Googling it, but cannot find proper solution!

请在android的EditText小部件中提供水印文本的实现,即使经过谷歌搜索,但找不到合适的解决方案!

回答by Mark Allison

If by "watermark text" you mean the text which appears in the field when it is empty, then use the attribute android:hint="My Text"in the layout or programmatically call setHint( "My Text" )on your EditTextobject.

如果“水印文本”是指在字段为空时出现在字段中的文本,则android:hint="My Text"在布局中使用该属性或以编程方式调用setHint( "My Text" )您的EditText对象。

回答by JOVI INTERNATIONAL

You can add a layout make its height and width fill_parentand make background transparent and add a TextViewas a water-mark in this layout.

您可以添加布局使其高​​度和宽度fill_parent并使背景透明,并TextView在此布局中添加一个作为水印。

I hope it can work.

我希望它可以工作。