Xml RelativeLayout TextInputLayout Imageview
<RelativeLayout
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relativeone"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:orientation="horizontal"
android:weightSum="5">
<android.support.design.widget.TextInputLayout>
android:id="@+id/layoutTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_vertical"
android:layout_weight="5"
android:gravity="center_vertical"
android:hint="Password"
android:paddingTop="4dp"
android:textColorHint="#3f3f3f">
<EditText
android:id="@+id/passwordedit"
android:layout_width="match_parent"
android:layout_height="60dp"
android:drawableLeft="@mipmap/bluelocked"
android:drawablePadding="13dp"
android:gravity="center_vertical"
android:inputType="textPassword"
android:paddingLeft="15dp"
android:textColor="#3f3f3f"
android:textColorHint="#3f3f3f"
android:textSize="13sp" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="@+id/imagepassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:paddingBottom="20dp"
android:paddingRight="10dp"
android:src="@mipmap/IMAGEYOUWANT" />
</RelativeLayout>
And in your activity, add a method onTouch()to display and remove your password.
ImageView imagepass = (ImageView) findViewById(R.id.imagepassword);
imagepass .setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
editpass.setInputType(InputType.TYPE_CLASS_TEXT);
break;
case MotionEvent.ACTION_UP:
editpass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
break;
}
return true;
}
});
source
share