2017-02-14 2 views
0

私はedittextにdrawableの左と右のアイコンを追加しました。描画可能なパスワードを表示または非表示に使用することができますが、描画可能な右のアイコンをクリックすると描画可能な左が見えなくなります。この問題を解決するにはどうすればよいですか?引き出し可能な左のアイコンが見えなくなりますか?

txtPassword.setOnTouchListener(new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      final int DRAWABLE_RIGHT = 2; 

      if (event.getAction() == MotionEvent.ACTION_UP) { 

       if (event.getRawX() >= (txtPassword.getRight() - txtPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { 
        if (IsHidePwd) { 
         txtPassword.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_show_pwd, 0); 
         txtPassword.setTransformationMethod(PasswordTransformationMethod.getInstance()); 

         IsHidePwd = false; 
         return true; 
        } else { 
         txtPassword.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_hide_pwd, 0); 
         txtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); 

         IsHidePwd = true; 
         return true; 
        } 
       } 
      } 
      return false; 
     } 
    }); 
+0

サイズをtxtPassword.setCompoundDrawablesWithIntrinsicBounds(10、10、R.drawable.ic_show_pwd、10)に指定しようとします。 それは私のために働く。 –

答えて

1

この行では、左側にもドロウアブルを設定する必要があると思います。

txtPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.left_img、0、R.drawable.ic_show_pwd、0);

+0

ありがとう.. !!! –

関連する問題