When I am add icon like below:
etComment = (EditText) findViewById(R.id.et_comment);
Drawable img = getResources().getDrawable( R.drawable.warning );
etComment.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );
The icon resizes EditText. How can I calculate img size and put it into EditText without EditText resize?
Thanks!
FunkTheMonk
Use setCompounDrawables() instead of setCompoundDrawablesWithIntrinsicBounds() - you'll have to set the bounds of the drawables manually.
I don't understand how to calculate Bounds manually. I have got height and width of EditText:
etComment = (EditText) findViewById(R.id.et_comment);
Drawable img = getResources().getDrawable( R.drawable.warning );
int size = etComment.getHeight();
img.setBounds(0, 0, size, size);
etComment.setCompoundDrawables( img, null, null, null );
but I have different results in different screen sizes. How I can calculate correct size and padding of icon? Could you please help me?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With