Android 使用主题资源
来源:互联网 发布:大学软件开发专业 编辑:程序博客网 时间:2024/05/21 09:16
1 与样式资源类似 Android的主题资源的xml文件通常放在/res/values 目录下,同样以<resource ../> 作为根元素,使用<style,,/>来定义主题
2 主题资源与样式资源的区别在于:
1 主题不能作用于单个的View组件,主体应该对整个应用的所有Activity起作用,或对指定的Activity起作用
2 主体定义的格式应该是改变窗口外观的格式
3 代码:
xml文件
<resources> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> <style name="my_style"> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> <item name="android:windowFrame">@drawable/window_border</item> <item name="android:windowBackground">@drawable/star</item> </style></resources>2 Activity
package com.example.themetest;import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setTheme(R.style.my_style);//设置主题setContentView(R.layout.activity_main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}如果想让自己的应用中的所有窗口都使用该主题,只要为Application元素添加android:theme属性
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/my_style" > <activity android:name="com.example.themetest.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>如果只想让程序中的某一个窗口使用该主题 ,可以修改该<Activity.../ >使用<android:theme>
<activity android:name="com.example.themetest.MainActivity" android:label="@string/app_name" <!-- 修改该Activity显示主题 --> android:theme="@style/my_style"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
0 0
- Android 使用主题资源
- 初学Android,使用主题(Theme)资源(二十一)
- Android 主题资源风格定制 <1>
- Android style(样式), theme(主题)资源
- Impact 主题(三):使用资源
- 样式资源(style)和主题的使用
- 轻松实现Android 更换皮肤(主题) - 资源打包为apk,使用AssetManager动态解析调用
- 样式、主题、原始XML资源、Android程序国际化、Menu资源
- Drawable资源---主题资源
- Android 使用主题(Theme)
- Android 使用主题(Theme)
- Android开发指南-框架主题-资源和资产
- Android入门——样式主题和自定义属性资源
- Android入门——样式主题和自定义属性资源
- Android系统自带主题的使用及自定义主题
- 2.4、Android Studio使用主题编辑器设计主题
- Android之资源使用
- Android使用LayerDrawable资源
- 最长递减子序列 【微软面试100题 第四十七题】
- Android Launcher3源码分析与修改
- Get和Post的区别
- JAVA——jdk安装
- #pragma once 与 #ifndef 解析
- Android 使用主题资源
- C++的特性
- Clickjacking简单介绍
- 判断点在多边形内的算法
- Log4J的应用
- linux screen
- 第11周项目6(3)-回文素数
- POJ-1005
- 余传林语录:传统人力资源管理功能逐渐消失,HR们该换职业还是转型……