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、效果如下:

Android中自定义漂亮动态样式

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

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

更多相关文章

  1. [置顶] android 自定义控件
  2. 关于基本控件TextView属性大全详解
  3. Android Theme主题样式开发注意点
  4. Android Button控件 的简单使用(button监听和onClick触发函数使用
  5. Android 自定义漂亮的Seekbar样式
  6. Android控件抖动效果
  7. Android瀑布流控件——AndroidStaggeredGrid
  8. 在Android当中常用的控件的详解和分析

随机推荐

  1. Android(安卓)TextView文字横向自动滚动(
  2. Android自己动手实现下拉刷新控件(1)----典
  3. React Native Android(安卓)ScrollView
  4. Android(安卓)网络安全配置
  5. 怎么样搭建Android开发平台
  6. Android零基础入门第15节:掌握Android(安
  7. Android赋予内置三方应用应用权限
  8. Android(安卓)架构组件的最新进展
  9. Android矢量图(二)--VectorDrawable所有
  10. TextView支持的XML属性及相关方法