Android Editbox提示-始终显示提示
我有一个带有提示的文本框,但我希望始终显示提示,即使TB中有输入。例如Gmail应用程序中的“To”字段。首先想到的是插入两个editText布局相对布局。 第一个在第二个之上。在那上面-把背景放在第二个之上 android.R.color.transparent 使用相对布局的顶部元素!在下面的项目中-设置提示(您想要的)并尝试放置文本。可能是您将指定顶部第一个元素的填充以增大显示 哦。还有一件事。Android Editbox提示-始终显示提示,android,xml,layout,Android,Xml,Layout,我有一个带有提示的文本框,但我希望始终显示提示,即使TB中有输入。例如Gmail应用程序中的“To”字段。首先想到的是插入两个editText布局相对布局。 第一个在第二个之上。在那上面-把背景放在第二个之上 android.R.color.transparent 使用相对布局的顶部元素!在下面的项目中-设置提示(您想要的)并尝试放置文本。可能是您将指定顶部第一个元素的填充以增大显示 哦。还有一件事。 可能会使用editText背景图像-但对可伸缩性不好。您可以使用3种方法(扰流板-使用编号3)
可能会使用editText背景图像-但对可伸缩性不好。您可以使用3种方法(扰流板-使用编号3),因为正如我在评论中提到的,在Gmail示例中,这并不是一个实际的提示:
<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>
<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>
注意:可能有问题,因为文本将显示在提示顶部,请参阅解决方案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"/>
结果如下图所示:
<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>
编辑:<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>
<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"/>
我不认为这是一个暗示,你可以看到光标只在“To”之后开始。但是,您可以通过使用线性布局来模拟它,如果您同意这种方法,我将编写一个完整的答案。听起来不错,您介意吗?没问题-添加了一个答案,我建议您使用选项3,如果您有任何问题,请告诉我。使用setOnFocusChangeListener