首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android界面-题目和按钮定制-drawable

2012-11-09 
Android界面-标题和按钮定制-drawable这篇文章记录了怎么使用drawable中的StateList来实现自定义标题 以及

Android界面-标题和按钮定制-drawable

这篇文章记录了怎么使用drawable中的StateList来实现自定义标题 以及 按钮,先看一下效果图吧:

Android界面-题目和按钮定制-drawable

先介绍一下drawable中的stateList

先看代码:

send_button.xml

 Android界面-题目和按钮定制-drawable

而stateList是一种drawable,所以上面的send_button.xml其实在android应用程序看来就是类似一张图片,不过这张图片是有状态的。 作为按钮,当点击这个控件时,它会提供一个友好的相应。

关于stateList,请参考官方文档:http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Tips: 定义中的状态的匹配是按照顺序进行的,匹配到第一个成功就不往下匹配了(这里我也不太清楚具体的应用场景,反正就是提醒,定义状态的顺序是比较重要的,也可以把这里的状态类比有着break的switch语句块)。状态的顺序很重要,文章有个例子,参考那个例子就可以了,而对于按钮,运用本文中的例子也可以了。


使用drawable

跟使用图片是一样的,直接上代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"     android:orientation="vertical"    android:background="@color/white">    <include layout="@layout/head"         android:layout_width="fill_parent"        android:layout_height="wrap_content"/>    <include        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:layout_marginTop="30sp"        layout="@layout/content" /></LinearLayout>


源代码位置:http://download.csdn.net/download/stalendp/4663132

热点排行