动态设置 drawable-left...

    xiaoxiao2021-12-14  21

    Drawable img_on, img_off;   Resources res = getResources();   img_off = res.getDrawable(R.drawable.btn_strip_mark_off);   //调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示   img_off.setBounds(00, img_off.getMinimumWidth(), img_off.getMinimumHeight());   btn.setCompoundDrawables(img_off, nullnullnull); //设置左图标   第二种方法 TextView fillDeductionActTextview = new TextView(getContext()); RelativeLayout.LayoutParams wrap2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); fillDeductionActTextview.setLayoutParams(wrap2); Drawable drawableLeft = ContextCompat.getDrawable(getContext(), R.mipmap.agent); fillDeductionActTextview.setCompoundDrawablesWithIntrinsicBounds(drawableLeft,null,null,null);
    转载请注明原文地址: https://ju.6miu.com/read-970157.html

    最新回复(0)