Summarize the correct way to play the theme in Android

 

Excerpted from: http://blog.csdn.net/u011791526/article/details/52066031

There is <application  Android :theme="@style/AppTheme"> in the AndroidManifest.xml file, where @style/AppTheme is the referenced theme style in res/values/styles.xml, and it may also be the referenced res/values -v11/styles.xml or res/values-v14/styles.xml, which is determined according to the mobile phone system running this program, if the API version of the mobile phone system is above 11, it is v11/styles.xml, and so on. In values/styles.xml, you will find that the theme style of AppTheme is inherited from AppBaseTheme, and the parent theme of AppBaseTheme is different. You can also modify the theme from this position. This article is mainly to discuss this theme How to modify.

It should be noted that as a beginner or specializing in researching the theme (Theme), you'd better delete values-v11 and values-v14 and values-vXX, so as not to be disturbed by these things.

 

There are three sources of topics:

1) Comes from the android system

2) from a compatibility package (such as v7 compatibility package)

3) Write a theme yourself

The first two are mainly discussed here, and the topic is not discussed by myself.

 

Use the theme that comes with the android system to add "android:", such as: android:Theme.Black
Use the theme in the v7 compatibility package without a prefix, directly: Theme.AppCompat

 

There will be automatic prompts when writing themes in Android Studio, but there will be no automatic prompts in Eclipse


The solution is not to write "android:Theme.Black", but to write "@android:style/Theme.Black" and you will be prompted
to write "@style/Theme.AppCompat" instead of "Theme.AppCompat"

Because style(@android:style/Theme.Black) and theme(android:Theme.Black) are still different in mission, in order to automatically prompt when writing in eclipse, you can write "@android:style/Theme. Black", but after writing it, remember to manually change it to "android:Theme.Black"

 

Now see what themes are

The system comes with themes:
API 1:
android:Theme root theme
android:Theme.Black background black
android:Theme.Light background white
android:Theme.Wallpaper desktop wallpaper as the background
android:Theme.Translucent transparent background
android:Theme.Panel Tablet style
android:Theme.Dialog dialog style

API 11:
android:Theme.Holo Holo root
themeandroid:Theme.Holo.Black Holo black
themeandroid:Theme.Holo.Light Holo white theme

API 14:
Theme.DeviceDefault 设备默认根主题
Theme.DeviceDefault.Black 设备默认黑主题
Theme.DeviceDefault.Light 设备默认白主题

API 21: (网上常说的 Android Material Design 就是要用这种主题)
Theme.Material Material根主题
Theme.Material.Light Material白主题


兼容包v7中带的主题:
Theme.AppCompat 兼容主题的根主题
Theme.AppCompat.Black 兼容主题的黑色主题
Theme.AppCompat.Light 兼容主题的白色主题

 

Theme.AppCompat主题是兼容主题,是什么意思呢?

意思就是说如果运行程序的手机API是21则就相当于是Material主题,如果运行程序的手机API是11则就相当于是Holo主题,以此类推

 

兼容包v7会被Google公司不断升级:
比如 appcompat-v7-21.0 表示升级到向 API 21 兼容
比如 appcompat-v7-23.2 表示升级到向 API 23 兼容


在eclipse中只能看到 appcompat_v7 后面没有跟API的版本号,如何识别呢?
可以在eclipse中展开v7项目的res文件夹,查看有没有values-21、values-23这样的文件夹,最大数字就是API版本号了。


所以同样是v7兼容包,会有API版本号不同的区别,要注意。

 

所有能应用于应用程序主题都是以“Theme.”开头
不是以“Theme.”开头的就不是应用程序主题,而是用于某些局部控件
比如“ThemeOverlay”主题,可用于 Toolbar 控件,这里不做深入分析了。
比如“TextAppearance”主题,可用于设置文字外观,这里不做深入分析了。
比如在v7中有很多以“Base”开头的主题,是一些父主题,不建议直接使用。

 


更多主题:
以下都是指“包含”,比如包含“Dialog”表示对话框风格
比如Theme.Dialog、Theme.Holo.Dialog、Theme.Material.Dialog、Theme.AppCompat.Dialog都是对话框风格
具体有没有这种组合,你就在“自动提示”中来看就可以,提示有就有,没有就没有。

Black Black style
Light Light style
Dark Dark style
DayNight Day style
Wallpaper Wallpaper background
Translucent Transparent background
Panel Flat style
Dialog Dialog style
NoTitleBar No TitleBar
NoActionBar No ActionBar
Fullscreen Fullscreen
MinWidth The width of the dialog or ActionBar changes according to the content, not full screen
WhenLarge dialog fills full screen
TranslucentDecor Translucent style
NoDisplay does not show, that is, hides
WithActionBar Shows ActionBar on older themes

Many themes will report errors when using them for many reasons. For example, the form must inherit AppCompactActivity, or inherit ActionBarActivty, or inherit FragmentActivity, or need to manually specify the width and height, or need to upgrade the minimum API version, or need a higher version of the SDK , or the compatibility package version is not equal.

 

Toss hard! ! !

 

The writing is not good, please criticize and correct.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326106044&siteId=291194637
Recommended