手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android控件系列之Shape使用方法
Android控件系列之Shape使用方法
摘要:如果你对Android系统自带的UI控件感觉不够满意,可以尝试下自定义控件,我们就以Button为例,很早以前Android123就写到过A...

如果你对Android系统自带的UI控件感觉不够满意,可以尝试下自定义控件,我们就以Button为例,很早以前Android123就写到过Android Button按钮控件美化方法里面提到了xml的selector构造。当然除了使用drawable这样的图片外今天Android开发网谈下自定义图形shape的方法,对于Button控件Android上支持以下几种属性shape、gradient、stroke、corners等。

复制代码 代码如下:我们就以目前系统的Button的selector为例说下:

<android:startColor="#ff8c00"

android:endColor="#FFFFFF"

android:angle="270" />

<android:width="2dp"

android:color="#dcdcdc" />

<android:radius="2dp" />

<android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

对于上面,这条shape的定义,分别为渐变,在gradient中startColor属性为开始的颜色,endColor为渐变结束的颜色,下面的angle是角度。接下来是stroke可以理解为边缘,corners为拐角这里radius属性为半径,最后是相对位置属性padding。

对于一个Button完整的定义可以为

复制代码 代码如下:

<xmlns:android="http://schemas.android.com/apk/res/Android">

<android:startColor="#ff8c00"

android:endColor="#FFFFFF"

android:angle="270" />

<android:width="2dp"

android:color="#dcdcdc" />

<android:radius="2dp" />

<android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

<android:startColor="#ffc2b7"

android:endColor="#ffc2b7"

android:angle="270" />

<android:width="2dp"

android:color="#dcdcdc" />

<android:radius="2dp" />

<android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

<android:startColor="#ff9d77"

android:endColor="#ff9d77"

android:angle="270" />

<android:width="2dp"

android:color="#fad3cf" />

<android:radius="2dp" />

<android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

提示,以上几个item的区别主要是体现在state_pressed按下或state_focused获得焦点时,当当来判断显示什么类型,而没有state_xxx属性的item可以看作是常规状态下。

【Android控件系列之Shape使用方法】相关文章:

Android APK文件在电脑(PC虚拟机)上面运行方法

解析Android中使用自定义字体的实现方法

Android的Touch事件处理机制介绍

Android中使用sax解析xml文件的方法

Android控件系列之ImageView使用方法

Android 使用新浪微博SSO授权

Android自定义控件之自定义属性

Android控件系列之RadioButton与RadioGroup使用方法

android之计时器(Chronometer)的使用以及常用的方法

Android控件系列之XML静态资源使用介绍

精品推荐
分类导航