android样式主题
A. Android如何定制主题
目的:
为了加强用户体验,增强品牌效应,使我们的产品有自己独特的风格,主题的定制将会是必然趋势……
然而Android原生系统是不支持主题定制的,所以如何来定制主题,如何做得更好,需要大家集思广益……
策略:
将介绍两种定制主题的机制:
1.根据Android Configuration Qualifier机制,加入我们自己的JRDTheme定制。
2.用主题包的形式,根据用户选择不同的主题,而加载不同主题包中的资源。
基本原理:
首先介绍方式一:
Android Configuration Qualifier
Android 系统为一个项目提供了多套可供选择的资源,通过命名特殊的资源文件夹来区别它们。系统在运行的时候,根据设备的当前配置为每个应用加载合适的资源。
这些不同的资源都是放在每个应用的res/目录下面的,特殊的命名方式是-:
: 资源文件夹的名字,与默认资源文件夹保持一致
: 根据设备不同配置,需要使用的资源文件夹名字
Android系统根据优先级的先后顺序已经支持多种Configuration Qualifier,如图1:
如何添加 Jrd Theme Resources
JrdTheme 的核心策略是当我们设定了不同的主题后,会自动的替换我们想要替换的资源(Framework&App)。具体步骤如下:
1. 工程师从UE哪里获得我们想要改变的主题资源,
2.把这些资源放到对应模块的res/目录下,以Contacts模块为例,假如我们想要定制drawable、color、layout。
原来在Contacts模块中默认的资源目录如下:
res/
layout/
main.xml
info.xml
drawable/
icon.png
values/
colors.xml
定制后的资源目录如下:
res/
layout/
main.xml
info.xml
layout-jrdthemexxx/
main.xml
info.xml
drawable/
icon.png
drawable-jrdthemexxx/
icon.png
values/
colors.xml
values-jrdthemexxx/
colors.xml
Notes: jrdthemexxx 是其中一个 主题的 Qualifier,如果有多个主题,那么将会有多个jrdthemexxx存在。
3.与原来一样编译这些模块,push到手机中即可。
这只是一个guide ,具体实现还要细化…… 目前在diablo、beetle上面已经用这种方式实现了……我在smartiii上尝试过,机制没问题,但是改动的范围太大了,比较麻烦。
方式二:
核心思想:系统中有多套主题资源包,并且应用可以用相同的资源ID来访问不同资源包中对应的资源。 Android原生系统的资源访问流程 对应用来说,资源访问主要有下面三种方
式:
第一、比较普遍的方式是使用xml定义,并且通过AAPT工具生成一个R文件,列出资源的索引来让Android系统自己去遍历整个资源树的方式来访问。
第二、通过Resources接口来访问,使用Resources类的getDrawable、getString等接口来获取资源。
第三、通过AssetManager类的接口去访问,使用这个类的open方法来返回一个InputStream对象得到资源。
其实这三个访问方式只是Android资源访问中整个流程中在不同层次对外提供的三个接口,到底层的实现都是殊途同归的。
因此我们实际上需要修改的部分主干是在访问资源具体路径前,按照当前系统主题设置访问不同资源APK下的文件
即是把原生Android中资源ID和资源文件路径之间一对一的关系改为一对多的关系。
例子如下:如果原有资源ID和资源文件路径关系为:
R.drawable.image01 = 0x7F020001
通过系统的资源查找之后找到文件路径为 /system/app/frameworks-res.apk下的res/drawable_hdpi/icon.png
在AssetManager native中去读取资源并上传。
那么我们需要做的是在传入路径去读取资源时把文件路径替换为/data/app/SystemTheme01.apk下的res/drawable_hdpi/icon.png
B. 如何在 Android 应用程序中使用自定义主题
Android 应用程序中使用自定义主题的方法:
1、新建一个项目 Lesson32_StyleAndTheme。
2、拷贝下面三张 Nine-Patch PNG图片到res/drawable目录下:
C. Android系统自带样式Theme总结
本文从网上复制,给自己做笔记的,摘自: http://blog.csdn.net/hongya1109110121/article/details/11985545
Android系统自带样式(@android:style/) (转)
1 android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
布局页面最上面 不会显示 android:icon="@drawable/ic_launcher"中的值和android:label="@string/app_name"的值。
2 android:theme="@style/AppTheme"
布局页面最上面 显示 android:icon="@drawable/ic_launcher"中的值和android:label="@string/app_name"的值。
其他
在数嫌并AndroidManifest.xml文件的activity中配置
1、android:theme="@android:style/Theme"
默认状态,即如果theme这里不填任何属性的时候,默认为Theme
2、android:theme="@android:style/Theme.NoDisplay"
任何都不显示。比较适用于只是运行了activity,但未显示任何东西
3、android:theme="@android:style/Theme.NoTitleBar“
背景主题的没有标题栏者岩的样式,默认如果没有设置的话,显示黑背景
4、android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
背景主题的没有标题栏且全屏的样式,默认为黑背景
5、android:theme="@android:style/Theme.Black"
默认状态下黑背景
6、android:theme="@android:style/Theme.Black.NoTitleBar"
黑背景主题的没有标题栏的样式
7、android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
黑背景主题的没有标题栏且全屏的样式
8、薯迹android:theme="@android:style/Theme.Light"
默认状态下亮背景,与上述黑背景Theme.Black相反
9、android:theme="@android:style/Theme.Light.NoTitleBar"
亮背景主题的没有标题栏的样式,与Theme.Black.NoTitleBar相反
10、android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
亮背景主题的没有标题栏且全屏显示的样式,与Theme.Black.NoTitleBa.Fullscreenr相反
11、android:theme="@android:style/Theme.Dialog"
对话框样式 将整个activity变成对话框样式出现
12、android:theme="@android:style/Theme.InputMethod"
Window animations that are applied to input method overlay windows
13、android:theme="@android:style/ Theme.Panel"
删除掉所有多余的窗口装饰,在一个空的矩形框中填充内容,作用范围相当于把dialog中的所有元素全部去掉,只是一个空的矩形框,且此为默认的样式
14、android:theme="@android:style/ Theme.Light.Panel"
删除掉所有多余的窗口装饰,在一个空的矩形框中填充内容,作用范围相当于把dialog中的所有元素全部去掉,只是一个空的矩形框,且默认是light的样式
15、android:theme="@android:style/Theme.Wallpaper"
使用墙纸做主题,默认状态。
16、android:theme="@android:style/ Theme.WallpaperSettings"
使用墙纸做主题,默认是使用将上一个界面调暗之后作为主题
17、android:theme="@android:style/ Theme.Light.WallpaperSettings"
使用墙纸做主题,默认Light状态
18、android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
使用墙纸做主题,且没有标题栏
19、android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
使用墙纸做主题,且没有标题栏,且全屏显示
20、android:theme="@android:style/Theme.Translucent"
半透明状态下的背景,将运行此activity之前的屏幕作为半透明状态作为此activity运行时的样式。
21、android:theme="@android:style/Theme.Translucent.NoTitleBar"
半透明状态下没有标题栏的背景,将运行此activity之前的屏幕作为半透明状态作为此activity运行时的样式。
22、android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
半透明状态下没有标题栏且全屏的背景,将运行此activity之前的屏幕作为半透明状态作为此activity运行时的样式。
摘自: http://blog.csdn.net/hongya1109110121/article/details/11985545
D. Android studio中如何修改应用程序的主题和样式
在Android 5.0时谷歌推出了一个新的设计语言Material Design。并用在了Android M的系统中。
在AndroidManifest.xml文件中有一个android:theme属性,该属性的作用就是设置应用程序的主题。
有关于如何设置主题样式更为详细的方法,我在一个叫做秒秒学的网站中有看到过,如果想要更加具体的了解,你可以去看看。
E. 如何修改Android App的样式风格
android中可以自定义主题和风格。风格,也就是style,我们可以将一些统一的属性拿出来,比方说,长,宽,字体大小,字体颜色等等。可以在res/values目录下新建一个styles.xml的文件,在这个文件里面有resource根节点,在根节点里面添加item项,item项的名字就是属性的名字,item项的值就是属性的值,如下所示:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
</resources>
style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/MyText"
android:text="测试一下下"/>
</LinearLayout>
说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
<style parent="@android:style/Theme" name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@drawable/icon</item>
<item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>
style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/MyText"
android:text="测试一下下"/>
</LinearLayout>
说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
<style parent="@android:style/Theme" name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@drawable/icon</item>
<item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>
可以看到这里写了一个继承自系统默认的Theme的主题,里面有3个属性,这里强调一下第三个属性的值的问题,这里打个问号,然后加前面的一个item的名字表示引用的是那个名字的值,也就是那个名字对应的图片。
然后我们在Manifest.xml里面的Application里面加一个Theme的属性,这个属性对应的就是我们上面写的Theme。
复制代码 代码如下:
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:theme="@style/CustomTheme">
<activity android:name=".TestStyle"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
上面的代码没有标题栏,背景和fram都是我们设置的图片。当然也可以在代码中设置主题:
复制代码 代码如下:
package com.test.shang;
import android.app.Activity;
import android.os.Bundle;
public class TestStyle extends Activity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.CustomTheme);
setContentView(R.layout.test_style);
}
}
F. 如何为Android studio设置自定义的主题样式
Android Studio默认主题IntelliJ,我们可以修改成黑色的Dracula的主题或者是Windows主题。 1、首先双击桌面AndroidStudio图标,打开Android Studio。 2、选择Android Studio菜单栏File——Settings选项 3、或者在工具栏中直接点击Settings设置图。详细的可以看看安卓巴士教程:http://www.apkbus.com/thread-463460-1-1.html
G. 如何设计自己的android应用主题风格
•android:theme="@android:style/Theme.Dialog" 将一个Activity显示为能话框模式
•android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏
•android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏
•android:theme="Theme.Light" 背景为白色
•android:theme="Theme.Light.NoTitleBar" 白色背景并无标题栏
•android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏
•android:theme="Theme.Black" 背景黑色
•android:theme="Theme.Black.NoTitleBar" 黑色背景并无标题栏
•android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏
•android:theme="Theme.Wallpaper" 用系统桌面为应用程序背景
•android:theme="Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏
•android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏
•android:theme="Translucent" 半透明
•android:theme="Theme.Translucent.NoTitleBar" 半透明、无标题栏
•android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、无标题栏、全屏
•android:theme="Theme.Panel"
•android:theme="Theme.Light.Panel"
H. Android开发主题样式详解
application标签中的@style/AppTheme引用自哪个文件夹中的styles.xml,这是根据运行此程序的手机系统来决定的,如果手机系统的API版本是11以上就是v11/styles.xml,API版本是14以上就是v14/styles.xml,以此类推。我们可以通过修改AppBaseTheme的父主题来实现我们需要的样式,此文章主要就是来讨论这个主题如何修改。
使用android系统中自带的主题要加上"android:",如:android:Theme.Black
使用v7兼容包中的主题不需要前缀,如:Theme.AppCompat
系统自带主题:
API 1:
android:Theme 根主题
android:Theme.Black 背景黑色
android:Theme.Light 背景白色
android:Theme.Wallpaper 以桌面墙纸为背景
android:Theme.Translucent 透明背景
android:Theme.Panel 平板风格
android:Theme.Dialog 对话框风格
API 11:
android:Theme.Holo Holo根主题
android:Theme.Holo.Black Holo黑主题
android:Theme.Holo.Light Holo白主题
API 14:
android:Theme.DeviceDefault 设备默认根主题
android:Theme.DeviceDefault.Black 设备默认黑主题
android:Theme.DeviceDefault.Light 设备默认白主题
API 21: (网上常说的 Android Material Design 就是要用这种主题)
android:Theme.Material Material根主题
android:Theme.Material.Light Material白主题
兼容包v7中带的主题:
Theme.AppCompat 兼容主题的根主题
Theme.AppCompat.Black 兼容主题的黑色主题
Theme.AppCompat.Light 兼容主题的白色主题
以下都是指“包含”,比如包含“Dialog”表示对话框风格
比如Theme.Dialog、Theme.Holo.Dialog、Theme.Material.Dialog、Theme.AppCompat.Dialog都是对话框风格
Black 黑色风格
Light 光明风格
Dark 黑暗风格
DayNight 白昼风格
Wallpaper 墙纸为背景
Translucent 透明背景
Panel 平板风格
Dialog 对话框风格
NoTitleBar 没有TitleBar
NoActionBar 没有ActionBar
Fullscreen 全屏风格
MinWidth 对话框或者ActionBar的宽度根据内容变化,而不是充满全屏
WhenLarge 对话框充满全屏
TranslucentDecor 半透明风格
NoDisplay 不显示,也就是隐藏了
WithActionBar 在旧版主题上显示ActionBar