TextInputLayout not showing EditText hint before user focus on it

后端 未结 16 837
时光说笑
时光说笑 2020-11-27 13:50

I am using recently released Android Design Support Library to show floating label with EditTexts. But i am facing the problem that the Hint on the EditText is not showing w

相关标签:
16条回答
  • 2020-11-27 14:00

    Update:

    This is a bug that has been fixed in version 22.2.1 of the library.

    Original Answer:

    As mentioned by @shkschneider, this is a known bug. Github user @ljubisa987 recently posted a Gist for a workaround:

    https://gist.github.com/ljubisa987/e33cd5597da07172c55d

    As noted in the comments, the workaround only works on Android Lollipop and older. It does not work on the Android M Preview.

    0 讨论(0)
  • 2020-11-27 14:03

    There is a simple solution to this as this worked for me

    <android.support.design.widget.TextInputLayout
        android:id="@+id/activity_login_til_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="27dp"
        android:layout_marginTop="24dp"
        android:padding="10dp"
        app:passwordToggleEnabled="true"
        app:passwordToggleTint="#000000"
        app:passwordToggleDrawable="@drawable/passwordviewtoggleselector"
        android:theme="@style/Base.TextAppearance.AppCompat">
          <!---- add this line and theme as you need ----->
        <android.support.design.widget.TextInputEditText
            android:id="@+id/activity_login_et_password"
            android:layout_width="match_parent"
            android:layout_height="58dp"
            android:hint="Password"
            android:inputType="textPassword"
            android:padding="10dp"
            android:textColor="#f5ab3a"
            android:textColorHint="#e6d2d1cf"
            android:textSize="20dp" />
    
    </android.support.design.widget.TextInputLayout>
    

    Just add android:theme="@style/Base.TextAppearance.AppCompat" to the TextEditLayout and it should work and you can change the theme as you need.

    0 讨论(0)
  • 2020-11-27 14:04

    Looks like this issue appears when you set onFousListener on EditText - try to extend EditText and support multiple onFocusListeners

    0 讨论(0)
  • 2020-11-27 14:04

    Just add: android:hint="your_hint" for TextInputLayout.

    0 讨论(0)
  • 2020-11-27 14:06

    That is a known bug of the Android Design library. It has been accepted and assigned.

    So you should have this fixed in the next Android Design library release.

    In the meantime, you could watch the issue tracker for a hacky-fix that might get posted there, but I don't know any as of now.

    And yes, it only affect Lollipop and above.

    0 讨论(0)
  • 2020-11-27 14:07

    This works for me in Design Library 23.1.1:

    Set the hint color in xml attributes of TextInputLayout:

        <android.support.design.widget.TextInputLayout
            ....
            android:layout_margin="15dp"
            android:textColorHint="@color/hintColor"
            android:layout_width="match_parent"
            ...
    
    0 讨论(0)
提交回复
热议问题