activity中设置button的图片

有时候直接设置background图片会变形

private Button btn;

btn= (Button)findViewById(R.id.btn);

Drawable drawable =ContextCompat.getDrawable(this,R.mipmap.test);

drawable.setBounds(0, 0,drawable.getMinimumWidth() ,drawable.getMinimumHeight());  //此为必须写的

btn.setCompoundDrawables(drawable, null, null, null);

猜你喜欢

转载自blog.csdn.net/zyw0101/article/details/78813842
今日推荐