Android-Styles and Themes [From API Guide]
This blog was opened 5 months ago and it has 57 posts now,but the poor thing is by now no one has commented on any articles by now..How miserable and pathetic...Even if I've been writing some bullshit you should at least give me some response...Never mind, I was originally meant to writer to remind myself.
And sometimes I feel a little reluctant to read English than Chinese, even when I carefully read them I feel they are illustrated so clearly even more explicit than many Chinese vague articles.When I learn something from google's developer.android.com , I want to note them here.But I think why, firstly, why should I note them when I can visit them any time on google's website; secondly ,why use Chinese?
There's a proverb in China called "A good memory is not as good as a broken pen point" ,meaning that one would remember something better when he or she write it down.Ok now I decide to write things down when I learn something from android developers.
-------------------------
Styles and Themes:
Styles in Android share a similar philosophy to cascading stylesheets in web design—they allow you to separate the design from the content.
For example, by using a style, you can take this layout XML:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:typeface="monospace"
android:text="@string/hello" />
And turn it into this:
<TextView
style="@style/CodeFont"
android:text="@string/hello" />
All of the attributes related to style have been removed from the layout XML and put into a style definition calledCodeFont
, which is then applied with the style
attribute.
A theme is a style applied to an entire Activity
or application, rather than an individual View
. When a style is applied as a theme, every View in the Activity or application will apply each style property that it supports. For example, you can apply the same CodeFont
style as a theme for an Activity and then all text inside that Activity will have green monospace font.
Define Styles
1.To create a set of styles, save an XML file in the res/values/
directory of your project. The name of the XML file is arbitrary, but it must use the .xml
extension and be saved in the res/values/
folder.(I thought it could be saved in any folder,is it just a recommendation?)
2.The root node of the XML file must be <resources>
.
3.For each style you want to create, add a <style>
element to the file with a name
that uniquely identifies the style (this attribute is required). Then add an <item>
element for each property of that style, with a name
that declares the style property and a value to go with it (this attribute is required). The value for the <item>
can be a keyword string, a hex color, a reference to another resource type, or other value depending on the style property. Here's an example file with a single style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
-----it's Tomb-sweeping Day , to be continued-----
Inheritance
You can use this to inherit properties from an existing style and then define only the properties that you want to change or add. You can inherit from styles that you've created yourself or from styles that are built into the platform.
For example, you can inherit the Android platform's default text appearance and then modify it:
<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
kind of like the "override" concept in Java huh..
Android-Styles and Themes [From API Guide]的更多相关文章
- TrineaAndroidCommon API Guide
android-common-lib 关于我,欢迎关注微博:Trinea 主页:trinea.cn 邮箱:trinea.cn#gmail.com 微信:codek2 主要包括:缓存( ...
- 【多端应用开发系列1.1.1 —— Android:使用新浪API V2】服务器Json数据处理——Json数据概述
[前白] 一些基础的东西本系列中就不再详述了,争取尽量写些必不可少的技术要点. 由于本系列把Web Service 构建放到了第二部分,Android项目就采用新浪微博API v2作为服务器端. [原 ...
- 在Android应用程序使用YouTube API来嵌入视频
在Android版YouTube播放器API使您可以将视频播放功能到你的Android应用程序.该API允许您加载和播放YouTube视频(和播放列表),并自定义和控制视频播放体验. 您可以加载或暗示 ...
- Android 8.0 功能和 API
Android 8.0 为用户和开发者引入多种新功能.本文重点介绍面向开发者的新功能. 用户体验 通知 在 Android 8.0 中,我们已重新设计通知,以便为管理通知行为和设置提供更轻松和更统一的 ...
- Django REST Framework API Guide 08
1.Filtering 2.Pagination FIltering GenericAPIView的子类筛选queryset的简单方法是重写.get_quueryset()方法. 1.根据当前用户进行 ...
- Django REST Framework API Guide 03
本节大纲 1.Routers 2.Parsers 3.Renderers Routers Usage from rest_framework import routers router = route ...
- Django REST Framework API Guide 01
之前按照REST Framework官方文档提供的简介写了一系列的简单的介绍博客,说白了就是翻译了一下简介,而且翻译的很烂.到真正的生产时,就会发现很鸡肋,连熟悉大概知道rest framework都 ...
- Android 9 新功能 及 API 介绍(提供了实用的模块化的功能支持,包括 人工智能)
Android 9(API 级别 28)为用户和开发者引入了众多新特性和新功能. 本文重点介绍面向开发者的新功能. 要了解新 API,请阅读 API 差异报告或访问 Android API 参考. ...
- 3.Appium运行时出现:Original error: Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device
参考博客:https://blog.csdn.net/niubitianping/article/details/52624417 1.错误信息:Original error: Android dev ...
随机推荐
- Aws Dynamodb数据导出到S3
本节将描写叙述怎样从一个或多个DynamoDB的表导出数据到S3的bucket中.在运行导出之前你须要提前创建好S3的bucket. 注意 假设你还没有使用过AWS Data Pipeline,在运行 ...
- Android自己定义实现循环滚轮控件WheelView
首先呈上效果图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- overflow滚动条样式设置,ie和webkit内核
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- mysql: 关于MySQL InnoDB锁行还是锁表?
baidu zone - 关于MYSQL Innodb 锁行还是锁表,深入讲解
- windows平台简易直播系统搭建
最近做直播系统的朋友很多,正好前端时间也在做这一块,写片文章分享下开发心得,以为后用. 直播系统我将它分为前堆推流,后台服务,客户端播放三大部分.前端推流基于ffmpeg,后台服务 使用crtmp服务 ...
- C#动态编译dll或exe
string strCode = @" using System; using System.Text; using System.Collections.Generic; using Sy ...
- 封装PDO操作数据库
<?php class DatabaseHandler { /** * sql语句查询 */ public static function query_data ($dataName,$sql, ...
- 笔记本POWER部分的应用——(MOS/LDO/BUCK BOOST)
一.MOSFET 简介: 金属-氧化物半导体场效应晶体管,简称金氧半场效晶体管(Metal-Oxide-Semiconductor Field-Effect Transistor, MOSFET)是一 ...
- 升级OpenSSL修复高危漏洞Heartbleed
升级OpenSSL修复高危漏洞Heartbleed 背景: OpenSSL全称为Secure Socket Layer.是Netscape所研发.利用数据加密(Encryption) ...
- Android 短信验证码控件
Android 短信验证码控件,便于项目中使用统一样式,统一提示改动.个人觉得挺好用的 <span style="font-size:18px;">public cla ...