【问题标题】:Set icon on button center position through programatically [closed]通过编程设置按钮中心位置的图标[关闭]
【发布时间】:2013-07-11 06:45:24
【问题描述】:

我想通过编程方式在中心位置的按钮上设置图标,如上图,请任何人帮助我...

【问题讨论】:

标签: android button icons


【解决方案1】:

愿这对你有帮助..

为 Drawable 文件夹中的按钮设置背景图像,然后使用以下代码:

btn.setBackgroundResource(R.drawable.image);

btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.image));

或使用: setCompoundDrawableWithIntrinsicBounds().

在其文档中查看更多关于 setCompoundDrawableWithIntrinsicBounds() 的信息:CLICK HERE

编辑:

试试这个方法: setCompoundDrawableWithIntrinsicBounds(R.drawables.minus,0,0,0);

在 XML 中添加这一行:android:paddingLeft="100dp"

【讨论】:

  • 对不起,我想设置按钮的图标中心
  • 阅读setCompoundDrawableWithIntrinsicBounds()的文档会帮助你..
  • 我读过它,但它只定义了设置图标左、右、下和上,如果你知道请告诉我...
  • 您必须在要设置图像的方法中指定整数值..
  • 欢迎 satheesh.. 如果我的回答对你有帮助,那就投票吧,伙计...
猜你喜欢
  • 2021-06-23
  • 1970-01-01
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 2016-04-12
  • 2020-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多