Android EditText 提示不显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3608234/
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
EditText hint doesn't show
提问by venuko
My EditTextconfigured as follows won't show the hint:
我EditText如下配置不会显示提示:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:hint="The hint..."
android:scrollHorizontally="true"
android:singleLine="true" />
It works if I set android:gravity="left"or if I remove android:scrollHorizontallyand android:singleLineattributes, which is not desirable. Any suggestions?
如果我设置android:gravity="left"或删除android:scrollHorizontally和android:singleLine属性,它会起作用,这是不可取的。有什么建议?
回答by Someone Somewhere
using android:ellipsize="end"fixed it for me
Weird bug !! (but Android has a lot of these weirdo bug)
使用android:ellipsize="end"它为我修复了奇怪的错误!(但 Android 有很多这些奇怪的错误)
回答by lal
In Lollipop version the default text and hint text color is white for EditText.
So we have to change like this in EditText
在 Lollipop 版本中,默认文本和提示文本颜色为白色EditText。所以我们必须像这样改变EditText
android:textColorHint="@color/grey"
回答by Kavi
I wanted my single-line EditTextbox to scroll but keep the hint on the right also.
I had the same issue and got the hint to stick by keeping gravity="right", and setting singleLine="true"and ellipsize="end".
我希望我的单行EditText框可以滚动,但也要将提示保留在右侧。我遇到了同样的问题,并通过保持gravity="right"、 设置singleLine="true"和得到了坚持的提示ellipsize="end"。
回答by Ravi Yadav
You need to give text color to hint
你需要给文本颜色提示
android:textColorHint="#000000"
回答by user2008534
Using android:ellipsize="end" resolves the obvious platform bug. Unfortunately, Xperias still misbehave :(
使用 android:ellipsize="end" 解决了明显的平台错误。不幸的是,Xperias 仍然行为不端:(
I found no other solution than to:
我没有找到其他解决方案:
if (android.os.Build.MANUFACTURER.matches(".*[Ss]ony.*"))
editText.setGravity(Gravity.LEFT);
else
editText.setGravity(Gravity.CENTER);
回答by Praveen
No need of android:scrollHorizontallyattribute. Remove it.EditTextis a fixed item on the screen. we want scroll the layout contains the EditText is enough. that is the best design too. you have put android:ellipsize="end"instead of android:scrollHorizontally.
不需要android:scrollHorizontally属性。去掉它。EditText是屏幕上的固定项目。我们想要滚动布局包含 EditText 就足够了。这也是最好的设计。你把android:ellipsize="end"而不是android:scrollHorizontally.
回答by Nandagopal T
This is how, I did for by EditTextto have hint in it.
这就是我所做的,因为EditText它有提示。
<EditText
android:id="@+id/productQuantity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right|center_vertical"
android:hint="@string/quantity"
android:inputType="numberSigned"
android:ellipsize="end"
android:singleLine="true" >
</EditText>


回答by Hossa The Coder
The below worked for me:
以下对我有用:
<EditText
android:id="@+id/UserText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/UserPassword"
android:layout_marginTop="85dp"
android:ems="10"
android:hint="@string/UserHint"
android:inputType="textPersonName"
android:singleLine="true"
android:text="@string/UserName" >
<requestFocus />
</EditText>
回答by Vinnicius Pereira
Try changing the hint text color, sometimes the hint color is the same as the background color
尝试更改提示文本颜色,有时提示颜色与背景颜色相同
android:textColorHint="@color/colorBlack"

