[Android] Add borders to Android Studio layouts or controls

Table of contents

1. Add an overall border to the control or layout

2. Add a single border to the control or layout


1. Add an overall border to the control or layout

Create a new drawable resource folder background_frame.xml in the drawable folder:

background_frame.xml:

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

    <solid android:color="#FFFFFF" />

    <stroke
        android:width="1dp"
        android:color="#000000" />

    <padding
        android:bottom="0.1dp"
        android:left="0.5dp"
        android:right="0.5dp"
        android:top="0dp" />
</shape>

Apply in layout file:

The effect is as follows: 

2. Add a single border to the control or layout

Create a new drawable resource folder background_line.xml in the drawable folder:

background_line.xml:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 连框颜色值 -->
    <item>
        <shape>
            <solid android:color="#000000" />
        </shape>
    </item>
    <!-- 主体背景颜色值 -->
   <item android:bottom="1dp">   <!--设置只有底部有边框-->
        <shape>
            <solid android:color="#ffffff" />
        </shape>
    </item>
</layer-list>

Apply in layout file:

The effect is as follows:

Simple and rude!

Thanks ლ(°◕‵ƹ′◕ლ)! ! !

Guess you like

Origin blog.csdn.net/yao_yaoya/article/details/128283824