• 自定义主题 假设我们我们对现有的样式不大满意 那么可在工程目录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="不玩了"

18 UI美化自定义主题样式代码的更多相关文章

  1. 18 UI美化自定义形状shape

    自定义某个控件的形状 如 圆角 巨型 环形 : 在工程文件的新建 res/drawable/shape文件(以下键一个圆角) <?xml version="1.0" enco ...

  2. sencha touch 扩展篇之使用sass自定义主题样式 (上)使用官方的api修改主题样式

    大家知道,sencha touch是通过我们写的js代码来动态渲染单页面生成一个个div+css的html页面来模拟app应用,那么既然是div+css结构的,我们就可以通过修改css样式来自定义我们 ...

  3. sencha touch 扩展篇之使用sass自定义主题样式 (下)通过css修改官方组件样式以及自定义图标

    上一讲我们讲解了如何使用官方的api来修改主题样式,这讲我们继续讲解sass的样式修改, 编译官方自带的主题包  在生成的项目以及官方sdk的目录下,自带了一些主题sass包,我们也可以通过修改sas ...

  4. 18 Ui美化

    资源文件的使用: 一: res中文件中放置的文件类型: res/drawable//放处理过的图片 res/drawable-XXX //放的Ui切得图 >res/anim 放动画 >re ...

  5. 18 UI美化之level(等级显示显示)

    根据level显示哪张图片 在工程文件的res/drawable/新建level-list 如下 <?xml version="1.0" encoding="utf ...

  6. 18 UI美化layer-list

    layer-list 用于叠加两张图片 或者设置 RatingBar(评分) 进度条 相框等 在工程文件中的res/drawable/新建一个layer-list(叠加两张图片) 如下 : <? ...

  7. 18 Ui美化 剪切动画clip

    输入0 - 10000 让图片根据数值显示部分图片 在工程文件的res/drawable/新建clip文件 <?xml version="1.0" encoding=&quo ...

  8. 18 UI美化transition 图片过渡

    让两张图片在一定时间过渡 在工程文件res/drawable/transition文件 <?xml version="1.0" encoding="utf-8&qu ...

  9. 18 UI美化状态集合的位图selector

    当我们某个控件 想在不同状态下显示不同的背景图的需求 如我们需要按钮在正常状态显示一种图 按下显示另一背景图 或者单选框被选中时是一种显示图片 没选中是另一种背景图 例子 按钮在不同状态显示不同的背景 ...

随机推荐

  1. Conjugate

    1.1Conjugate问题描述在不存在的 noip day3 里,小 w ⻅到了一堆堆的谜题.比如这题为什么会叫共轭?他并不知道答案.有 n 堆谜题,每堆有 a i 个,小 w 每次从剩下的谜题中选 ...

  2. [HAOI2012]道路

    题目描述 C国有n座城市,城市之间通过m条[b]单向[/b]道路连接.一条路径被称为最短路,当且仅当不存在从 它的起点到终点的另外一条路径总长度比它小.两条最短路不同,当且仅当它们包含的道路序列不同. ...

  3. Chtholly Nota Seniorious

    题目背景 大样例下发链接: https://pan.baidu.com/s/1nuVpRS1 密码: sfxg こんなにも.たくさんの幸せをあの人に分けてもらった だから.きっと 今の.私は 谁が何と ...

  4. ●POJ 2079 Triangle

    题链: http://poj.org/problem?id=2079 题解: 计算几何,凸包,旋转卡壳 复杂度O(N^2),(O(N)什么的就不说了,我觉得我看过的O(N)方法正确性都有问题,虽然有些 ...

  5. 【NOIP2013】华容道 广搜+spfa

    题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少需要多少时间. 小 ...

  6. poj 3348 Cow 凸包面积

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description ...

  7. NOI2017游记

    Day -1: THUSC后,下定决心好好学习,不过由于自制力太弱,还是没有忍住浪了几次. 老师把NOI前的天分为了4种:考试日.交流日.讲课日.自习日. 考试日是我被郭神短神妖神任神常神尹神龙神游神 ...

  8. Linux(CentOs6.3)网络配置

    新装好的虚拟机往往还无法连接网络,本文描述了如何在CentOs6.3系统上配置网络信息 1.windows系统下快捷键windows+r,输入cmd并确定,打开黑窗口 2.黑窗口中输入ipconfig ...

  9. K-means聚类 的 Python 实现

    K-means聚类 的 Python 实现 K-means聚类是一个聚类算法用来将 n 个点分成 k 个集群. 算法有3步: 1.初始化– K 个初始质心会被随机生成 2.分配 – K 集群通过关联到 ...

  10. Jenkins简明入门(三) -- Blue Ocean,让一切变得简单

    我们在上一节Jenkins简明入门(二) 中见识到了Jenkins能做些什么:利用Jenkins完成python程序的build.test.deployment. 同时,也有一种简单的方法,不需要写J ...