2016-03-01 157 views
0

我试图搜索这个很多,但是我无法制作与android图片中相同的按钮。如何制作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和按钮是透明的白色边框 如果有人能够帮助我,这将是一个很大的帮助。

+0

它不透明,因为你已经用'ee' alpha –

+0

@ cricket_007定义了你的颜色,我删除了这两个'ee'仍然不会给我上面的图片中的漂亮圆角和透明度 – Nant

+0

你能上传它目前的样子?我认为你只是有一个带有圆角的“白色”按钮,是的? –

回答

2

定义形状是正确的做法。如果你希望它是透明的白色边框,你需要避免使用固体标签并使用中风(即边框)。

因此,例如,你都会有这样的形状(我们称之为bg_button.xmldrawable文件夹下):那么这

<?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编辑器上渲染圆角会产生问题。

+0

感谢它也适用于我! :) –

0

目前,它看起来像这样

enter image description here

我想EditTexts和按钮是透明带白色边框

通过使用下面的代码:

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

    <!--<solid android:color="#ffffff" />--> 

</shape> 

我得到以下问题:

enter image description here

正如你可以在侧面看到有灰色区域....

+1

定义形状是正确的方法。正如我在其他评论中给你写的,如果你想让它与边框一起透明,你需要避免使用'solid'标签并使用'stroke'(即边框)。因此,例如:'' – thetonrifles

+0

请将此编辑为您的问题,因为它不是答案。 –

+0

如何将其更改为编辑? @ cricket_007 – Nant