如何制作android圆形按钮

时间:2016-03-01 22:21:50

标签: android button

我试图搜索这个但是我无法为Android中的图片制作相同的按钮。

enter image description here

我一直在尝试使用以下代码,但按钮不是透明的,并且它的边缘没有那么好的圆角:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#ffffff" />
    <corners android:radius="15dp" />
</shape>

目前它看起来像这样

enter image description here

我希望EditTexts和按钮透明,带有白色边框 如果有人可以帮助我,这将是一个很大的帮助。

1 个答案:

答案 0 :(得分:3)

定义形状是正确的方法。如果您希望它是透明的白色边框,则需要避免使用实体标签并使用笔划(即边框)。

例如,您将拥有此形状(让我们在bg_button.xml文件夹下将其称为drawable):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:color="@android:color/white" android:width="1dp" />
    <corners android:radius="15dp" />
</shape>

然后将此应用于您的视图作为背景。这是一个例子:

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Facebook"
    android:background="@drawable/bg_button"/>

请不要只在Android Studio编辑器上尝试,也可以在您的模拟器/设备上尝试。在Android Studio编辑器上渲染圆角可能会产生问题。