Skip to content

Latest commit

 

History

History
43 lines (37 loc) · 1.47 KB

自定义背景.md

File metadata and controls

43 lines (37 loc) · 1.47 KB

自定义背景

  1. 自定义一个背景颜色,让颜色从左到右变化的那种 在res-drawable目录下新建一个xml文件。里面xml文件内容的根节点是shape

    <?xml version="1.0" encoding="utf-8"?>
    	<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    	android:shape="rectangle">  //指定样式这里rectangle就是指定长方形
    	<corners android:radius="3dip"></corners>  //指定边角的弧度
    	//颜色渐变,这里指定了开始、中间、结束三个颜色,样式就会从开始的比较淡变成中间的比较深,
    	<gradient android:startColor="#33000000"
    		android:centerColor="#bb000000"
    		android:endColor="#33000000"
    		></gradient>
    
    	<padding                              
    		android:top="2dip"
    		android:bottom="2dip"
    		></padding>
    		
    	<stroke android:width="4dip"    //stroke用于指定边线
    		android:color="#ff0000"
    		android:dashWidth="3dip"    //dashWidth就是将边线变成了虚线的宽度
    		android:dashGap="2dip"      //虚线的间距
    	</stroke>
    </shape>
  2. 自定义一个实心的小圆点

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    	android:shape="oval" >//指定是椭圆,我们只要在使用的时候讲宽高设置为相等就是园了
    	<corners android:radius="5dip" />
    	<solid android:color="#88000000" /> //填充颜色
    </shape>