Android 如何创建带有边框和透明背景的按钮

Android 如何创建带有边框和透明背景的按钮,android,ios,android-studio,user-interface,button,Android,Ios,Android Studio,User Interface,Button,如何在android中创建这种只有边框且透明的按钮,如下图中的“添加”按钮 另外,这是一张来自卢德米拉·舍甫琴科旅行应用程序的照片。虽然屏幕截图是ios的,但我希望在android中实现这一点。如何操作?您应该在如下所示的xml文件中创建一个形状,并将其设置为按钮背景 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" &g

如何在android中创建这种只有边框且透明的按钮,如下图中的“添加”按钮


另外,这是一张来自卢德米拉·舍甫琴科旅行应用程序的照片。虽然屏幕截图是ios的,但我希望在android中实现这一点。如何操作?

您应该在如下所示的xml文件中创建一个形状,并将其设置为按钮背景

 <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
        >
        <solid android:color="@android:color/transparent" />

        <stroke
            android:width="2dp"
            android:color="@color/your_border_color" />
    </shape>
<Button
                android:id="@+id/button_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="USE Button"
                android:background="@drawable/button_round"
                android:textColor="@color/yellow"
        />

按钮\u round.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true" >

    <shape android:shape="rectangle">
        <corners android:radius="5dp"/>
        <stroke android:width="1dp"
                android:color="@color/yellow"/>
    </shape>

</item>

<item>

    <shape android:shape="rectangle">
        <corners android:radius="4dp"/>
        <stroke android:width="1dp"
                android:color="@color/yellow"/>

    </shape>
</item>
</selector>

现在将此应用于您的按钮背景

 <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
        >
        <solid android:color="@android:color/transparent" />

        <stroke
            android:width="2dp"
            android:color="@color/your_border_color" />
    </shape>
<Button
                android:id="@+id/button_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="USE Button"
                android:background="@drawable/button_round"
                android:textColor="@color/yellow"
        />

您可以使用Shape Drawable实现这一点

在可绘制文件夹中创建一个形状
按钮\u background.xml
,如下所示:

<shape shape="rectangle">
    <stroke width="2dp" color="@android:color/white" /> // You may change color as per your need
    <solid color="@android:color/transparent" />
</shape>

//你可以根据需要改变颜色
将此绘图应用于按钮背景属性,如下所示:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/button_background"
    android:drawableStart="@drawable/ic_plus" />


ic\u plus
是您的项目所需的图标。

到目前为止您尝试过任何东西吗?可能重复的事实上没有。因为我是编程新手,完全没有想法。只需点击
按钮
并分配文本
添加
现在在可绘制中创建一个
xml
文件并创建“矩形”形状的边框并将
按钮指定为@Axlr的背景