TextView、UIButton、EditText自定义背景边框

一、main.xml
<?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">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:textSize="24pt"
        android:background="@drawable/bg_border"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="24pt"
        android:text="圆角边框、渐变背景的文本"
        android:background="@drawable/bg_border2"
        />
</LinearLayout>
//1.指定背景  res\layout\main.xml
android:background="@drawable/bg_border"

//2.bg_border实现 res\drawable/bg_borde
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#0000"></solid>
    <stroke android:width="4px" android:color="#f00"></stroke>
</shape>

//1.指定背景 res\layout\main.xml
 android:background="@drawable/bg_border2"

//2.bg_border2实现  res\drawable/bg_borde2
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  //指定圆角矩形的4个圆角的半径
  <corners
        android:topLeftRadius="20px"
        android:topRightRadius="5px"
        android:bottomRightRadius="20px" />
//设置边框颜色
    <stroke android:width="4px" android:color="#f0f"
        />
//设置渐变颜色
    <gradient android:startColor="#f00"
        android:centerColor="#0f0"
        android:endColor="#00f"
        android:type="sweep"/>
</shape>


实现效果

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。