1、XML方式

  1. <Button android:drawableLeft="@drawable/btn_strip_mark_on"></Button>
复制代码

2、JAVA代码

  1. Drawable img_on, img_off;
  2. Resources res = getResources();
  3. img_off = res.getDrawable(R.drawable.btn_strip_mark_off);
  4. // 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示
  5. img_off.setBounds(0, 0, img_off.getMinimumWidth(), img_off.getMinimumHeight());
  6. btn.setCompoundDrawables(img_off, null, null, null); //设置左图标
复制代码

相关文章:

  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-08-18
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
相关资源
相似解决方案