CompoundDrawable size

后端 未结 6 2021
臣服心动
臣服心动 2020-12-08 14:32

Android-Lint gives me this hint in some cases:

This tag and its children can be replaced by one and a compound drawable

I cou

6条回答
  •  时光说笑
    2020-12-08 15:01

    Programmatic solution:

    You can use drawable.setBounds but it requires pixels rather than dp as parameters.

    how to convert: Converting pixels to dp

    code:

            Drawable drawable = getDrawable(R.drawable.ic_your_drawable);
            int size = dp2px(this, dpSize);
            if (drawable != null) {
                drawable.setBounds(0, 0, size, size);
            }
    
            textView.setCompoundDrawables(drawable, drawable, drawable, drawable);
    

提交回复
热议问题