給控件加個圓框

在drawable文件夾下建一個xml文件: 比如 demo.xml

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

    <!-- 設置圓角 -->
    <corners android:radius="10dp"/>

    <!-- 描邊 -->
    <stroke android:color="#ff0"
            android:width="3dp"
        />
</shape>
然後在控件中引用:

android:background="@drawable/demo"


當然還有其他的屬性:比如

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

    <!-- 設置圓角 -->
    <corners android:radius="10dp"/>


    <!-- 描邊 -->
    <stroke android:color="#ff0"
            android:width="3dp"
        />

    <!-- 內容與邊框的間距 -->
    <padding
        android:right="3dp"
        android:left="3dp"
        android:top="4dp"
        android:bottom="4dp"
        />

    <!-- 設置內容區的背景 -->
    <solid android:color="#F00"/>



</shape>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章