• 自定义主题 假设我们我们对现有的样式不大满意 那么可在工程目录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. 【BZOJ1060】【ZJOI2007】时态同步

    Description 小Q在电子工艺实习课上学习焊接电路板.一块电路板由若干个元件组成,我们不妨称之为节点,并将其用数字1,2,3-.进行标号.电路板的各个节点由若干不相交的导线相连接,且对于电路板 ...

  2. ●BZOJ 2555 SubString

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2555题解: 后缀自动机+LCT 不难发现,对于输入的询问串,在自动机里trans后的到的状态 ...

  3. BZOJ4079 [Wf2014]Pachinko

    完整题面: 设f(i,j)表示路径经过(i,j)这个点的概率,列出方程消元. 但暴力消元的复杂度是$O((nm)^3)$,注意每一次消元只会影响前后m个方程,所以我们可以对于第i行,只存[i-m,i+ ...

  4. 求n的阶乘

    import java.util.Scanner; public class J {  public static void main(String args[])  {   //注释:int n=6 ...

  5. js添加key为数字的对象,通过类似于通过访问数组的中括号形式访问对象属性

    var obj={};obj[1] = "mm";obj[2]="nn";console.log(obj[1]); 同var obj={};obj[" ...

  6. mybatis自动生成

    很简单只要配两个文件 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmln ...

  7. axios的兼容性处理

    一.简介 看看官网的简介: "Promise based HTTP client for the browser and node.js" 译:基于 Promise 的 HTTP ...

  8. vue mint-ui 实现省市区街道4级联动(仿淘宝京东收货地址4级联动)

    demo及源码地址 https://github.com/artiely/citypicker 先去下载一个“省份.城市.区县.乡镇” 四级联动数据,然后 引入 import { Picker } f ...

  9. Java实现23种设计模式

    一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接 ...

  10. C# IE浏览器

    引用Microsoft HTML Object Library 引用 -> com -> Microsoft HTML Object Library 引用后,显示如图 1.判断ie浏览器是 ...