goGud goGud - 3 months ago 16
Android Question

Designing password text with show password button

I am trying to design

EditText
for password with show password imageView. However I cannot design it correctly beacuse I cannot see
ImageView
, since
EditText's layout_width="fill_parent"
. When I change it to
wrap_content
, I can see my
ImageView
but then it looks very bad in UI. Is it possible to design it without giving fixed size?

Here is my code;

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:layout_marginBottom="8dp">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">

<EditText
android:id="@+id/registerPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/register_password"
android:inputType="textPassword" />
<ImageView
android:id="@+id/fragment_login_password_visibility"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@android:drawable/ic_partial_secure"
android:layout_gravity="center"
android:clickable="true"/>

</LinearLayout>
</android.support.design.widget.TextInputLayout>


EDIT:

android:layout_weight=1 solved issue. Now I can see ImageView left of EditText. However now, I TextInputLayout hint is not working.

Here Hint works

Here Hint does not works

Answer

First set android:weightSum of LinearLayout to "1". Then, set android:layout_width and android:layout_weight of EditText to "0dp" and "1", respectively.