Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Editbox提示-始终显示提示_Android_Xml_Layout - Fatal编程技术网

Android Editbox提示-始终显示提示

Android Editbox提示-始终显示提示,android,xml,layout,Android,Xml,Layout,我有一个带有提示的文本框,但我希望始终显示提示,即使TB中有输入。例如Gmail应用程序中的“To”字段。首先想到的是插入两个editText布局相对布局。 第一个在第二个之上。在那上面-把背景放在第二个之上 android.R.color.transparent 使用相对布局的顶部元素!在下面的项目中-设置提示(您想要的)并尝试放置文本。可能是您将指定顶部第一个元素的填充以增大显示 哦。还有一件事。 可能会使用editText背景图像-但对可伸缩性不好。您可以使用3种方法(扰流板-使用编号3)

我有一个带有提示的文本框,但我希望始终显示提示,即使TB中有输入。例如Gmail应用程序中的“To”字段。

首先想到的是插入两个editText布局相对布局。 第一个在第二个之上。在那上面-把背景放在第二个之上 android.R.color.transparent 使用相对布局的顶部元素!在下面的项目中-设置提示(您想要的)并尝试放置文本。可能是您将指定顶部第一个元素的填充以增大显示

哦。还有一件事。
可能会使用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>
    
    
    
  • 使用相对布局,得到一个模仿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>
    
    注意:可能有问题,因为文本将显示在提示顶部,请参阅解决方案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>
    
  • 使用可拉伸的

    这似乎是一个更好的解决方案(我个人刚刚通过剪切TextView的1:1显示创建了它,将以正确的方式进行测量),这将允许更清晰的布局代码,并且文本将知道可绘制的:

    <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