[英]Android: How to place an edge around the button
所以我想讓我的按鈕有黑色背景的白色邊緣/邊框,在我的 xml 中有一個簡單的解決方案嗎?
是的,在您的 res/drawable 目錄中創建一個新的 XML 文件。 然后通過 XML 創建一個可繪制的形狀:這是一個帶有 2 像素白色邊框的 3 像素圓角黑色矩形的示例:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:radius="3"
/>
<stroke
android:width="2"
android:color="#FFFFFFFF"
/>
<solid
android:color="#FF000000"
/>
</shape>
然后只需將此可繪制對象設置為按鈕的背景,例如:
<Button
android:background="@drawable/my_xml_file"
/>
開發者網站有一個很好的參考,通過 XML 創建Shape Drawables 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.