如何在android中添加边框按钮



你好,我用按钮覆盖了ImageView,但是它们彼此靠得很近,你看不出它是按钮,它只是一个红色的大方块。我需要一个快速和简单的方法来给我的按钮边界/边缘或其他东西,这样你就可以看到不同的按钮。

在可绘制资源中创建形状

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
   <solid android:color="#C0213A" />`<!--Background Color-->`
   <stroke android:width="2dip" android:color="#C0213A"/> `<!--Border-->`
</shape>

在XML

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:background="@drawable/your_shape"> `<!--This is your shape created--`>

按钮没有边框,但是你可以使用shape来创建一个可绘制的边框,然后把它作为按钮的背景。

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

最新更新