Editbox Hint - Always show hint

后端 未结 2 1761
半阙折子戏
半阙折子戏 2021-01-21 01:56

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.

相关标签:
2条回答
  • The first thing that came to mind is to insert two editText layout relative layout. First over second.at the top of that - put background as android.R.color.transparent Work with top elevent of relative layout! In item below - set hint(that you want) and try to put text. May be you will have specify padding of first element of top to greate display.

    Oh. And one more thing. Maybe put to editText background background image - but is the bad to scalability.

    0 讨论(0)
  • 2021-01-21 02:38

    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. Using a Linear Layout, getting a cleaner look in my opinion:

      <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>
      
    2. Using a Relative Layout, getting a result that mimics the Gmail App:

      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"/>    
      

      Result are as shown in this image:

      Custom Permanent Hint

      Edit:

    3. using a Drawable:

      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"/>    
      

      Drawable Hint

    0 讨论(0)
提交回复
热议问题