18 UI美化自定义主题样式代码
来源:互联网 发布:橱柜哪个牌子好 知乎 编辑:程序博客网 时间:2024/05/22 08:24
- 自定义主题 假设我们我们对现有的样式不大满意 那么可在工程目录res/values下的styles.xml自定义
方法:
1. res/values下的styles.xml文件中自定义一个标签
<style name ="你想要取的样式名" parent="你想继承的样式"> <item name="重写的属性名">新属性</item> <item name="...">...</item> . .</style>
例子: styles.xml文件增加的字段
<color name="customcolor">#b0b0ff</color> <!-- 自定义的主题 name ="主题的名称 " parent="继承于 系统主题" 改变背景颜色 --> <!-- parent="@style/android:Theme.Light" 也可以写成 parent="android:Theme.Light" --> <style name="CustomTheme" parent="@style/android:Theme.Light"> <!-- 这里必须自定义一个color放入 不然报错 --> <item name="android:windowBackground">@color/customcolor</item> </style>
使用:在清单文件中AndroidManifest.xml中apliction或者activity中使用(如果activity没有定义主题那么默认使用apliction的)
例子:
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.qf.day18_resource_demo.MainActivity" android:label="@string/app_name" android:theme="@style/CustomTheme" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
关于继承样式两种方式
- 方式一
<style name="father"> <item name="android:textColor">#f00</item> <item name="android:layout_width">wrap_content</item> </style> <!-- 继承父类所有属性 并且可重写父类属性 --> <style name="father.son"> <item name="android:layout_width">wrap_content</item> </style>
调用方式
<activity android:name="com.qf.day18_resource_demo.MainActivity" android:label="@string/app_name" android:theme="@style/father.son" >
- 方式二
<style name="father"> <item name="android:textColor">#f00</item> <item name="android:layout_width">wrap_content</item> </style> <!-- 继承父类所有属性 并且可重写父类属性 --> <style name="son" parent="@style/father"> <item name="android:layout_width">wrap_content</item> </style>
- 调用
<activity android:name="com.qf.day18_resource_demo.MainActivity" android:label="@string/app_name" android:theme="@style/son" >
- 假设我们有一天很多控件的样式都是一样的 我们可以抽取样式放入style中
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/holo_red_light" android:text="抽奖" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/holo_red_light" android:text="再来一次" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/holo_red_light" android:text="不玩了" />
- 上面的例子可以看到三个Button有多个重复样式 ,那么我们现在抽取公共样式 于
目录res/values下的styles.xml自定义
<style name="MyButtonStyle"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name=" android:textColor">@android:color/holo_red_light</item> </style>
使用方法:
<Button style="@style/MyButtonStyle" android:text="抽奖" /> <Button style="@style/MyButtonStyle" android:text="再来一次" /> <Button style="@style/MyButtonStyle" android:text="不玩了"
0 0
- 18 UI美化自定义主题样式代码
- Android代码练习:自定义样式和主题
- 18 UI美化自定义形状shape
- android 自定义主题样式
- android 自定义主题样式
- 自定义android主题样式
- android自定义主题样式
- android 自定义主题样式
- vscode 自定义主题样式
- 样式和主题&自定义样式和主题
- 样式和主题 + 自定义样式和主题
- HTML radio自定义美化样式。
- jquery UI datepicker 弹出位置样式自定义代码样例
- 18 Ui美化
- android自定义style主题样式
- android---(样式、主题、自定义组件)
- android自定义style主题样式
- 样式主题与自定义View
- 16年9月14日谈
- Python2.7当中《笨办法学 Python》ex13.py报错的处理办法
- Android ADB常用命令整理
- Java中的main()方法详解
- C++实现两个大数相减
- 18 UI美化自定义主题样式代码
- windows下让自己的程序调用caffe库
- 能划分两子集合,每个集合的和相等
- JS中string方法中常用方法之二:String.prototype.concat()
- 2016年下半年规划
- Android小项目之倒计时工具的实现
- spring Invalid content was found starting with element 'init- param'
- HTML 图像
- 字符串日期与秒数互转