Calculate image size when using setCompoundDrawables for EditText

后端 未结 3 540
深忆病人
深忆病人 2021-01-17 17:16

When I am add icon like below:

etComment = (EditText) findViewById(R.id.et_comment);
Drawable img = getResources().getDrawable( R.drawable.warning );
etComme         


        
3条回答
  •  情书的邮戳
    2021-01-17 18:00

    I think you can use different size of pics for different screens and use getMinimumWidth to set Bounds.But I did not try it before , may be it is not appropriate for .9 patch.

    When you use setCompoundDrawables , you need code like :

    Drawable img;
    Resources res = getResources();
    img = res.getDrawable(R.drawable.btn_img);
    //You need to setBounds before setCompoundDrawables , or it couldn't display
    img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());
    btn.setCompoundDrawables(img_off, null, null, null); 
    

提交回复
热议问题