键入

时间:2016-10-05 06:57:19

标签: android android-edittext

我希望我的应用能够在不同的时间在edittext中显示不同的提示,所以我必须在每次按照语法设置提示,如下所示。

editText.setHint("Hint 1");

但问题是当我开始输入时,提示开始消失。我想每次都显示此提示。如果我在xml中设置提示,它不会在打字时消失,但在我的情况下如何做到这一点。

6 个答案:

答案 0 :(得分:4)

你应该考虑改为TextInputLayout(强烈推荐这个。Here is an example too.

使用EditText进行相对布局以进行输入,使用TextView进行内部提示。根据需要更改textview。

<RelativeLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Some text"
            android:layout_alignParentLeft="true"
            android:id="@+id/editText1"
            android:layout_gravity="center"
            />
    <TextView
            android:id="@+id/text_hint"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="yourHint"
            android:textSize="14sp"
            android:layout_marginRight="10dp"
            android:textColor="@color/customColor"
            />
</RelativeLayout>

答案 1 :(得分:2)

您所期望的是不可能的,因为我们必须知道用户在editext上写的内容。 现在是https://github.com/hardik-trivedi/FloatingLabel天 这种类型的提示更受欢迎,你可以尝试上面的链接。

答案 2 :(得分:1)

TextInputLayoutEditText提供强大的素材功能。主要功能是浮动提示。请参阅此处的文档https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html

答案 3 :(得分:1)

在Android中的编辑文本提示中键入文本时,您无法显示

<android.support.design.widget.TextInputLayout android:theme="@style/TextLabel" android:id="@+id/input_layout_username" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/username_edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" android:hint="Email Address" android:inputType="textEmailAddress" android:translationY="10dp" android:textColor="@color/white" android:textColorHint="@color/white" android:textSize="@dimen/font_13"/> </android.support.design.widget.TextInputLayout>

这里android提供默认功能,同时在编辑文本中键入文本上面的提示编辑文本,你也可以通过编程方式设置提示

 EditText. setHint ("Hint 1");

答案 4 :(得分:0)

执行此操作的最佳方法是使用TextInputLayout。

https://www.bignerdranch.com/blog/becoming-material-with-android-design-support-library/

答案 5 :(得分:0)

GET /eventsdata/EventDataType/_search
{
    "query": {
        "filtered": {
            "query": {
                        "regexp": {
                            "description": {
                                "value": ".*AppName=MyApplication.*"
                            }
                        }

                    }

        }
    }
}

并且不要忘记将此行添加到您的gradle文件

{
   "took": 19,
   "timed_out": false,
   "_shards": {
      "total": 1,
      "successful": 1,
      "failed": 0
   },
   "hits": {
      "total": 0,
      "max_score": null,
      "hits": []
   }
}