android style资源,Android 资源简介(八) Style 资源

一个样式相当于多个属性设置的集合,其他 UI 组件通过 style 属性来指定样式,这就相当于把该样式包含的所有属性设置同时应用于该 UI 组件。

Android 的样式资源文件放在 /res/values 目录下,样式资源文件的根元素是 ,该元素可以包含多个

name:指定样式的名称。

parent: 指定样式所继承的父样式。

下面是一个简单的使用示例,首先是自定义的 Style 内容,将它加在 /res/values 目录下的 styles.xml 文件中:

@color/colorPrimary

@color/colorPrimaryDark

@color/colorAccent

20sp

@color/colorPrimaryDark

#EEEE66

8dp

#000000

主布局文件的内容如下:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/colorGray"

android:orientation="vertical"

android:id="@+id/container"

>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:text="@string/testStyle01"

style="@style/test_style01"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:text="@string/testStyle02"

style="@style/test_style02"

/>

主程序文件的代码:

package com.toby.personal.testlistview;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

final private static String TAG = "Toby_Test";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

}

程序的运行效果:

11f2338cde80

运行效果

参考文献:《疯狂Android讲义(第2版)》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值