简体   繁体   English

如何使用setCompoundDrawables在右侧设置两个图标?

[英]How to set two icons on right side with setCompoundDrawables?

  public void showEyeIcon(){
        mDrawable = ContextCompat.getDrawable(getContext(), R.drawable.show_eye_black_24dp);
        setIcon();
    }

    public void showFingerprintIcon(){
        fingerprintDrawable = ContextCompat.getDrawable(getContext(), R.drawable.show_eye_black_24dp);
        setIcon();
    }

    private void setIcon() {
        Drawable[] drawables = getCompoundDrawables();

        setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], mDrawable, fingerprintDrawable);

        setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        setSelection(getText().length());
    }

I tried this way to set two icons on the right side. 我尝试过这种方法在右侧设置两个图标。 But its not working. 但是它不起作用。 Its messing up the alignment of the whole editText by going down and everything moves up. 它通过向下移动并使所有内容向上移动,从而弄乱了整个editText的对齐方式。 How it can be done? 怎么做?

You can't apply 2 drawables into the same direction. 您不能将2个可绘制对象应用到同一方向。 You can achieve it creating a custom EditText and in your layout build this 2 start drawables with your EditText, or create one drawable with these two icons. 您可以通过创建自定义EditText来实现,并在您的布局中使用EditText创建这2个开始可绘制对象,或者使用这两个图标创建一个可绘制对象。 You choose the best way for you 您选择最适合自己的方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM