如何设置转角半径在Java中code中的按钮? [英] How to set corner radiuses for the button in java code?
本文介绍了如何设置转角半径在Java中code中的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想设置的圆角没有XML。我怎样才能做到这一点在Java code?
I want to set the rounded corners without xml. How can I do it in java code?
Button b = new Button (this);
b.set???? (??) ;
我试着写b.setCornerRadius(3.0F),但它是不确定的按钮对象。 谢谢你。
I tried to write b.setCornerRadius(3.0f), but it is undefined for button object. Thanks.
推荐答案
在您绘制文件夹中创建一个形状并设置所需的半径,并将此作为绘制背景的按钮:
create a shape in your drawable folder and set the desired radius and set this drawable as background to your button:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="5dip"/>
</shape>
</item>
</layer-list>
这篇关于如何设置转角半径在Java中code中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文