• 自定义主题 假设我们我们对现有的样式不大满意 那么可在工程目录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. ●BZOJ 4596 [Shoi2016]黑暗前的幻想乡

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4596 题解: 容斥,矩阵树定理,矩阵行列式 先说说容斥:(一共有 N-1个公司) 令 f[i ...

  2. UVALive - 3938:"Ray, Pass me the dishes!"

    优美的线段树 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring& ...

  3. 【Codeforces Round #435 (Div. 2) A B C D】

    CF比赛题目地址:http://codeforces.com/contest/862 A. Mahmoud and Ehab and the MEX ·英文题,述大意:      输入n,x(n,x& ...

  4. CSS3中三种清除浮动(float)的方法

    方法一:添加新的元素 .应用 clear:both .clear{ clear:both; height:; height:; overflow:hidden; } 方法二:父级div定义 overf ...

  5. 在 telnet 中利用HTTP协议传递GET、POST参数

    HTTP协议不仅可以用在浏览器中,还可以用在任何支持它的地方,平时用浏览器访问网站时HTTP协议内容是隐藏起来看不到的,用 telnet 就能揭开它的神秘面纱.telnet 开启方法参考文章末尾——t ...

  6. Python中模块之os的功能介绍

    Python中模块之os的功能介绍 1. os的变量 path 模块路径 方法:os.path 返回值:module 例如:print(os.path) >>> <module ...

  7. C语言预备作业

    一.关于师生关系 第一种:我认为师生关系不是仅仅的餐馆与食客的关系,因为食客可以给餐馆评分,也可以选择是否继续在这里吃,但是学生却不可以选择老师,因为老师是传授知识的,无法由自己来选择.而学生是需要完 ...

  8. linux安装ftp

    安装vsftpd 1.以管理员(root)身份执行以下命令 1.  yum install vsftpd 2.设置开机启动vsftpd ftp服务 1.  chkconfig vsftpd on 3. ...

  9. 原生js之canvas时钟组件

    canvas一直是前端开发中不可或缺的一种用来绘制图形的标签元素,比如压缩上传的图片.比如刮刮卡.比如制作海报.图表插件等,很多人在面试的过程中也会被问到有没有接触过canvas图形绘制. 定义 ca ...

  10. SpringBoot学习之启动探究

    SpringApplication是SpringBoot的启动程序,我们通过它的run方法可以快速启动一个SpringBoot应用.可是这里面到底发生了什么?它是处于什么样的机制简化我们程序启动的?接 ...