Reputation: 461
I am trying to use a floating label in Android Studio and it is working sometimes and not others, the hint only shows once you click on the edit text otherwise it won't show. I would like it to show the password hint like the email one before you click it
<android.support.design.widget.TextInputLayout
android:id="@+id/EmailLayout"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:theme="@style/TextLbl">
<android.support.design.widget.TextInputEditText
android:id="@+id/emailInput"
android:layout_width="200dp"
android:layout_height="40dp"
android:ems="10"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:textSize="20sp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PassLayout"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/EmailLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:theme="@style/TextLbl">
<android.support.design.widget.TextInputEditText
android:id="@+id/passInput"
android:layout_width="200dp"
android:layout_height="40dp"
android:ems="10"
android:hint="@string/password"
android:inputType="textPassword"
android:textSize="20sp" />
</android.support.design.widget.TextInputLayout>
I cannot see what is wrong with this code
Upvotes: 1
Views: 1096
Reputation: 1106
Try this one:
<android.support.design.widget.TextInputLayout
android:id="@+id/PassLayout"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/EmailLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:theme="@style/TextLbl">
<android.support.design.widget.TextInputEditText
android:id="@+id/passInput"
android:layout_width="200dp"
android:layout_height="40dp"
android:ems="10"
android:hint="@string/password"
android:inputType="textPersonName"
android:textSize="20sp" />
</android.support.design.widget.TextInputLayout>
in Java file:
PassLayout.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
Hope this help you..if you need any help you can ask.
Upvotes: 1
Reputation: 2176
that's because you're using android:inputType="textPassword"
in the password edittext. Try using:
android:gravity="center"
android:ellipsize="start"
Upvotes: 0
Reputation: 4445
Try to change your code by using below Code : (Its Workable code )
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
app:passwordToggleEnabled="true"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="textPassword"
android:hint="Password"
android:drawableLeft="@null"
/>
</android.support.design.widget.TextInputLayout>
or you can set Hint by java on your Activity class as :
passwordEt.setHint("Password");
Upvotes: 0