<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/activity_logo_edit_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="@dimen/margin_top"
android:hint="请输入密码"
android:inputType="textPassword"
android:textColorHint="@color/colorWhite" />
<ImageButton
android:id="@+id/activity_login_seePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/design_ic_visibility"
android:layout_alignRight="@+id/activity_logo_edit_password"
android:layout_margin="20dp"
/>
</RelativeLayout>
if (!flag) {
// display password text, for example "123456"
editPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
eyeButton.setBackground(getResources().getDrawable(R.drawable.design_ic_visibility_off));
} else {
// hide password, display "."
editPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
eyeButton.setBackground(getResources().getDrawable(R.drawable.design_ic_visibility));
}
flag = !flag;
editPassword.postInvalidate();