Android中自定义漂亮动态样式

下面给大家演示制作工款精美的控件样式,可以应用到多种控件上。

1、在res中新建个drawable文件夹,然后在这文件夹上右击选择“新建”-“其它”-“Android Xml File”-“下一步”-输入文件名“my_style”,然后在下面选择“selector”。然后打开这个Xml文件,里面添加为如下:

  

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" >     <item>         <shape>             <corners android:radius="10px"/>             <gradient android:startColor="#f00" android:centerColor="#0f0" android:endColor="#00f"></gradient>                         <stroke android:width="2px" android:color="#ff0"></stroke>         </shape>     </item>     <item android:state_active="true">         <shape>             <corners android:radius="5px"/>             <gradient android:startColor="#000" android:centerColor="#0f0" android:endColor="#fff"></gradient>                         <stroke android:width="2px" android:color="#f0f"></stroke>         </shape>     </item> </selector>

  说明:纷色字体内容为您手动添加的。第一个item的内容表示默认样式,第二个item由于标注了:android:state_active="true",所以表示激活状态下的样式。根局自己的爱好,可以手动设计更多的样式,更多的item。

2、在layout布局Xml中,给对应控件添加样式:以TimePicker为例,添加 android:background="@drawable/my_style" />个:

    <TimePicker         android:id="@+id/timePicker1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignLeft="@+id/button1"         android:layout_below="@+id/button1"         android:layout_marginTop="41dp"         android:background="@drawable/my_style" /> 

当然了,给按钮也呆以添加android:background="@drawable/my_style" 来应用样式。

3、效果如下:

。。。好了,发挥你的才智吧。我这里只是抛砖引玉,思路就是这样,大家好好发挥。

本文来自宋兴柱博客员:http://www.cnblogs.com/songxingzhu/

更多相关文章

  1. [置顶] android 自定义控件
  2. Android(安卓)Layout XML属性
  3. 关于基本控件TextView属性大全详解
  4. Android系统多媒体框架添加对.wma格式的支持
  5. android中ListActivity使用记录Your content must have a ListVi
  6. Android中的常用控件之进度条(ProgressBar)
  7. Android(安卓)中自定义控件和属性(attr.xml,declare-styleable,T
  8. 【Android】19.3 ContentProvider及安卓进一步封装后的相关类
  9. Android(安卓)4.1.2系统添加重启功能

随机推荐

  1. android 全面讲解BroadCastReceiver
  2. 选项卡片段
  3. android 设置壁纸几种方法
  4. android菜单参考资料
  5. android操作xml
  6. Android多媒体开发(5)————利用Android(
  7. Android内核的根文件系统
  8. Android动画一
  9. Android常见错误解析
  10. Android(安卓)常用布局