TextView代码设置drawable

LayerDrawable drawable = (LayerDrawable) getResources().getDrawable(R.drawable.shape_lock_battery);
    drawable.setLayerInset(1, 6, (int) batteryPix, 6, 6);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    mBinding.tvBattery.setCompoundDrawablePadding(20);
    mBinding.tvBattery.setCompoundDrawables(drawable, null, null, null);

 

你可能感兴趣的:(Android)