Android studio 给控件画边框

会有一股神秘感。 提交于 2019-12-20 23:52:01

先记一个下载常用logo的网站

阿里图标库


1、添加全边框

在drawable 目录下新建一个drawable资源文件,内容如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--    主题颜色背景经颜色-->
<!--    <solid android:color="#f00"/>-->

    <!-- 连框宽度和颜色值 -->
    <stroke
        android:width="1dp"
        android:color="#000" />
</shape>

效果如下
在这里插入图片描述

再到要添加边框的控件中设置background属性,应用这个drawable资源文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:gravity="center_horizontal">

   <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:orientation="horizontal">
       <EditText
           android:layout_marginTop="10dp"
           android:layout_width="300dp"
           android:layout_height="30dp"
           android:hint="请输入用户名"
           android:background="@drawable/border"
           />
   </LinearLayout>

</LinearLayout>

在这里插入图片描述
这样就添加完了。

2、添加单个或多个的上下左右边框,用layer-list样式
新建一个drawable资源文件,代码如下














在这里插入图片描述

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!