如何在android中为按钮添加边框

FiF*_*TeR 1 android button imageview

嗨,我用按钮覆盖了我的 ImageView,但是当它们彼此靠近时,你无法分辨它是按钮,它只是一个大红色方块。我需要一种快速简便的方法来为我的按钮设置边框/边缘或其他东西,以便您可以看到不同的按钮。

Che*_*fes 6

在可绘制资源中创建一个形状

<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>
Run Code Online (Sandbox Code Playgroud)

在您的 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--`>
Run Code Online (Sandbox Code Playgroud)