Android 通过编程将图标设置在按钮中心位置
我想通过编程将图标设置在中央位置的按钮上,如上图所示,请任何人帮助我…这对您有帮助吗 为Drawable文件夹中的按钮设置背景图像,然后使用以下代码:Android 通过编程将图标设置在按钮中心位置,android,button,icons,Android,Button,Icons,我想通过编程将图标设置在中央位置的按钮上,如上图所示,请任何人帮助我…这对您有帮助吗 为Drawable文件夹中的按钮设置背景图像,然后使用以下代码: btn.setBackgroundResource(R.drawable.image); 或 btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.image)); 或使用:setCompoundDrawableWithIntrinsicBounds()。 请在其文档中
btn.setBackgroundResource(R.drawable.image);
或
btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.image));
或使用:setCompoundDrawableWithIntrinsicBounds()。
请在其文档中查看有关setCompoundDrawableWithIntrinsicBounds()
的更多信息:
编辑:
试着这样做:设置复合DrawablewithintrinsicBounds(R.drawables.减号,0,0,0)代码>
在XML:android:paddingLeft=“100dp”中添加此行
Button类的文档说明了什么?可能重复的我不知道我是新来的Android如果你不知道答案,请阅读并走开…可能重复的抱歉我想设置按钮的图标中心阅读SetCompoundDrawable WithIntrinsicBounds()的文档
它将帮助您..我阅读了它,但它只定义了设置图标左、右、下和上,如果您知道,请告诉我..您必须在该方法中指定整数值,以便设置图像..欢迎使用satheesh。。如果我的回答对你有帮助,那么就投它一票,伙计。。。