Android 开发指南翻译开篇--User Interface -Styles and Themes

8 篇文章 0 订阅
8 篇文章 0 订阅

先定一个学习计划吧,准备把Android的开发指南重新看一遍,借博客做个记录吧。


User Interface -Styles and Themes

用户接口-样式和主题


定义:

style:style is a collection of properties that specify the look and format for a View or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.

style:是View或window的关于外观和格式的属性集合。样式的定义在xml中,在layout中指定样式,二者隔离。

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#00FF00"
    android:typeface="monospace"
    android:text="@string/hello" />
可转化为:

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />

Theme:theme is a style applied to an entire Activity or application, rather than an individual View (as in the example above). 

Theme:是一种应用到整个Activity或Application中的style.



Defining Styles

1、文件存储:在res\values下,以xml存储。

<?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>
    style name--指定sytle名字,parent--继承style名

2、样式的继承

2.1 使用parent方法

2.2 使用分隔符方法,只能继承自己定义的样式。

    <style name="CodeFont.Red">
        <item name="android:textColor">#FF0000</item>
    </style>
3、属性值定义item


3.1有哪些属性值,2种方法:

>可以去查看相关视图类的说明,其中有一节:xml Atributes 这些属性都可以定义。

>see the R.attr reference


3.2有些属性只能给作为theme的style使用

>参看R.attr中window开头的属性

>A list of the standard attributes that you can use in themes can be found at R.styleable.Theme.


注意属性前加上:"android:"

Applying Styles and Themes to the UI

应用样式和主题


1、style 在layout的xml中,指定view的style

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />


2、theme 在manifiest中为<activity><application>指定android:theme属性

<application android:theme="@style/CustomTheme">
<activity android:theme="@android:style/Theme.Dialog">
<activity android:theme="@android:style/Theme.Translucent">

Using Platform Styles and Themes

使用Android提供的Styles和Themes

You can find a reference of all available styles in the R.style class.To use the styles listed here, replace all underscores in the style name with a period. For example, you can apply the Theme_NoTitleBar theme with "@android:style/Theme.NoTitleBar".
>所有可用的styles,可以查看R.style类,使用这些styles时,下划线要改成圆点。
>查看styles.xml和themes.xml原代码(我在原代码中未找到这2个文件)





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值