android中的shape属性

来源:互联网 发布:药智网红外光谱数据库 编辑:程序博客网 时间:2024/06/07 02:23

在android自带的控件中如按钮,输入框都不如ios的控件好看,我们一般都会仿照ios的控件的效果。只需在drawable目录下新建一个xml文件,修改控件的样式。

如button_shape.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <!--点击背景-->    <item android:state_pressed="true">        <shape>            <!--色值-->            <solid android:color="#e79429" />            <!--圆角-->            <corners android:radius="10dp" />        </shape>    </item>    <!--默认背景-->    <item>        <shape>            <solid android:color="#f6aa3e" />            <corners android:radius="10dp" />        </shape>    </item></selector>

把它设为按钮的背景,其效果:
这里写图片描述

一、android中的shape的标签中的属性有corners、gradient、padding、size、solid、stroke等。
1、Corners是用来字义圆角的,其中radius与其它四个并不能共同使用。。

<corners    //定义圆角       android:radius="dimension"      //全部的圆角半径       android:topLeftRadius="dimension"   //左上角的圆角半径       android:topRightRadius="dimension"  //右上角的圆角半径       android:bottomLeftRadius="dimension"    //左下角的圆角半径       android:bottomRightRadius="dimension" />    //右下角的圆角半径 

2、solid(实心的) 用以指定内部填充色。

<solid  android:color="color" /> 

3、gradient(梯度)用以定义渐变色,可以定义两色渐变和三色渐变,及渐变样式。

<gradient      android:type=["linear" | "radial" | "sweep"]    //共有3中渐变类型,线性渐变(默认)/放射渐变/扫描式渐变       android:angle="integer"     //渐变角度,必须为45的倍数,0为从左到右,90为从上到下       android:centerX="float"     //渐变中心X的相当位置,范围为0~1       android:centerY="float"     //渐变中心Y的相当位置,范围为0~1       android:startColor="color"   //渐变开始点的颜色       android:centerColor="color"  //渐变中间点的颜色,在开始与结束点之间       android:endColor="color"    //渐变结束点的颜色       android:gradientRadius="float"  //渐变的半径,只有当渐变类型为radial时才能使用       android:useLevel=["true" | "false"] />  //使用LevelListDrawable时就要设置为true。设为false时才有渐变效果 

4、stroke这是描边属性,可以定义描边的宽度,颜色,虚实线等。

    <stroke                android:width="dimension"   //描边的宽度           android:color="color"   //描边的颜色           // 以下两个属性设置虚线           android:dashWidth="dimension"   //虚线的宽度,值为0时是实线           android:dashGap="dimension" />      //虚线的间隔  

5、size和padding 这两个基本上不怎么用,因为他们所具有的功能,控件本身也能实现。

二、Shape的属性(rectangle、oval、line、ring ;矩形,还有椭圆形,线形和环形),Shape定义自已当前Shape的形状。

参考链接:http://www.cnblogs.com/MianActivity/p/5867776.html 。

0 0
原创粉丝点击