我如何编程圆一个按钮,Android的? [英] How do I round a button programmatically in Android?
问题描述
我有一个按钮
使用自定义适配器的号召, getView其中填充一个
。因此,没有为 GridView控件
()按钮没有.xml文件
。
I have a Button
which populates a GridView
using a custom adapter's call to getView()
. As such, there is no .xml file for the Button
.
有没有一种方法以编程方式圆按钮
Is there a way to programmatically round the Button
?
推荐答案
使用九补丁,下面是一个例子之一:
Use a nine patch, here is an example one:
它保存在你的 / RES /绘-MDPI /
与文件名目录 btn_round.9.png
save this in your /res/drawable-mdpi/
directory with the filename btn_round.9.png
然后在你的java code做到这一点:
then in your java code do this:
mBtn.setBackgroundResource(R.drawable.btn_round);
因为它是9补丁机智将延伸到适合任何内容您的按钮内推杆。搜索机器人draw9patch来了解更多关于如何创建9补丁文件。
because it is 9 patch wit will stretch to fit whatever content you are putting inside the button. Search for "android draw9patch" to learn more about how to create the 9 patch files.
这篇关于我如何编程圆一个按钮,Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!