动态设置TextView的drawable属性

来源:互联网 发布:电视剧后期制作软件 编辑:程序博客网 时间:2024/05/22 14:02

Drawable drawable = ContextCompat.getDrawable(this, R.drawable.state_icon_error);
方法1.
mTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);//使用固定大小的drawable
方法2.
drawable.setBounds(0, 0, 50, 50);//必须设置图片大小,否则不显示
mTextView.setCompoundDrawables(drawable, null, null, null);

(提示:Drawable drawable = getResources().getDrawable(R.drawable.img);
方法已经过时了,使用ContextCompat.getDrawable替代)

原创粉丝点击