我想设置一个带有图案的动态按钮,可以随程序运行的状态和图片上方的文本变化而改变。如果我用ImageButton,连文本都无法添加。如果用Button,我可以添加文本,但是只能用android:drawableBottom设定图片和一些XML的相关属性。然而这些属性只能将文本和图片在二维空间里结合在一起,也就是说,我只能在文本周围添加图片,但不能将图片置于文本下方。
我应该怎么解决这个问题呢?
原问题:Android: combining text & image on a Button or ImageButton
Answer: Vitaly Polonetsky
(Best answer)
You can set setBackgroundDrawable() on Button to add a background to the button. Any text can be placed above the background. If you need some xml related content, you can use the android:background attribute.
Answer: OneWorld
The following method mainly solves the operation of adding background, icon and text on a button:
If you want to achieve more complex effects, you can use RelativeLayout to set its clickability.
Answer: schlingel
I think there are some better solutions, just take a normal Button and do it with drawableLeft and gravity properties:
In this way, a button button will appear on the left side of the button, and the article will be on the right side of the button, centered.
Answer: CMA
Just use
Alternative
That’s it