0
edittext의 양쪽 끝에 드로어 블을 추가했습니다. 오른쪽 드로어 블을 클릭하면 왼쪽 드로잉이 사라집니다.edittext에 두 개의 드로어 블
etPassword.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (event.getRawX() >= (etPassword.getRight() - etPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
if (etPassword.getInputType() == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
etPassword.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD);
etPassword.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_visibility_off_white_24dp, 0);
etPassword.setSelection(etPassword.getText().length());
} else {
etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
etPassword.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_visibility_white_24dp, 0);
}
return true;
}
}
return false;
}
});
: 기본적으로 글고 치기는 고정 input.Icon 암호와 아이콘의 가시성 (눈) 바로 당김에 대한
리스너 구현이 암호의 가시성에 따라 글고 respectivily.The 오른쪽 아이콘 토글의 왼쪽과 오른쪽에 있습니다입니다
XML :
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/et_bg"
android:drawableRight="@drawable/ic_visibility_off_white_24dp"
android:hint="@string/password"
android:drawableLeft="@drawable/ic_lock_white_24dp"
android:inputType="textPassword"
android:maxLines="1"
android:padding="10dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/textColorPrimary" />
스크린 샷 : | 시작에 lock_icon 추가
글고 etPassword.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_visibility_off_white_24dp, 0);
의 왼쪽 아이콘 위치 |
무엇이 문제입니까> –
오른쪽 아이콘은 쇼 암호를 전환하고 숨기기위한 아이콘입니다. 왼쪽 아이콘은 무엇을위한 것입니까 ??? –
@Sagar Nayak 님이 스크린 샷 – musica