簡體   English   中英

如何在Android中為按鈕添加邊框

[英]How to add border to button in 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--`>

按鈕沒有邊框,但是您可以使用形狀制作帶有邊框的可繪制對象,然后將其作為按鈕的背景。

<?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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM