编辑框提示 - 始终显示提示 [英] Editbox Hint - Always show hint

查看:133
本文介绍了编辑框提示 - 始终显示提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个提示一个文本框,但我想一直显示的提示,即使是在结核病的输入。例子是在Gmail应用程序的收件人字段。

I have a textbox with a hint but I want the hint to always be shown, even when there is an input in the TB. Example is the "To" field in the Gmail app.

推荐答案

有可以使用的方法3(扰流板 - 使用3号),因为在我的评论在Gmail中的例子提到,它不是一个实际的提示

There are 3 approaches you could use (spoiler - use number 3), since as mentioned in my comment, in the Gmail example , it is not an actual hint:


  1. 使用线性布局,渐渐在我看来,一个简洁的外观:

<LinearLayout android:layout_width="fill_parent"
          android:layout_height="wrap_content">
<TextView android:text="@string/Hint"
          android:layout_margin="5dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
<EditText android:layout_width="fill_parent"
          android:inputType="text"
          android:layout_height="wrap_content"/>    
</LinearLayout>


  • 使用相对布局,让模仿的Gmail应用程序的结果:

    注意:,因为文本将在提示的顶部显示,请参阅解决方案3可能会出现问题。

    Note: might be problematic since the text will be displayed on top of the hint, see solution 3.

    <RelativeLayout android:layout_marginTop="10dp"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content">
        <TextView android:text="@string/Hint"
              android:paddingLeft="10dp"
              android:layout_marginBottom="0dp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"/>
        <EditText android:layout_width="fill_parent"
              android:inputType="text"
              android:layout_height="wrap_content"/>    
    

    结果:

    编辑:

    使用可绘制

    这似乎是一个更好的解决方案(我个人刚刚从剪断1中创建它:TextView的1显示,将在正确的测量这种方式),这将允许一个清晰的布局code和文本将是意识到绘制的:

    This seems a better solution (I personally just created it from snipping the 1:1 display of the TextView, will be in correct measurements this way), this will allow a cleaner layout code, and the text will be aware of the drawable:

    <RelativeLayout android:layout_marginTop="10dp"
         android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              >
    <EditText android:layout_width="fill_parent"
              android:inputType="text"
              android:gravity="top"
              android:drawableLeft="@drawable/Hint"
              android:layout_height="wrap_content"/>    
    

    这篇关于编辑框提示 - 始终显示提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆