Android default theme

血红的双手。 提交于 2019-12-04 17:26:07

问题


I am making one android application but i was thinking about themes..

If i don't declare a theme of my Android application which theme will be used? Where i can find this information? What is the criteria for use one and other?

I was thinking about, if i want customize my all application, i have to extend one theme and custom all item that i want to customize.

And what if it assumes one of them as default? Weather I have to customize it again? How do i know what is the default one?


回答1:


The default theme varies depending on the API level (to be consistent with the general UI).

On API < 10, the theme was a set of styles (as in the link below) known as Theme, above that API 10, the default theme was Theme_Holo and now, starting with API 21, the default theme has become Theme.Material.

  • API < 10: see the frameworks's code Theme or Theme.AppCompat
  • 10 >= API < 21: read the Styles and Themes guide Holo_Theme or Theme.AppCompat
  • API >= 21 Using the Material Theme guide Theme.Material

Most of those styles are available through the android.support libraries.

PS: AFAIK the light theme has always been the default one.




回答2:


It is best to define a default theme yourself instead of relying on android to pick the default theme. This is because different versions of android may have completely different default themes, and could mess up your layouts.

You can declare a theme for your application in AndroidManifest.xml

<application android:theme="@style/MyTheme" .....>

Then in res/values folder, you edit/add a file themes.xml and add something like the following:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="MyTheme" parent="@android:style/Theme.Holo">
         ... customize your theme here
    </style>
</resources>

You can edit the parent of your theme to anything you want...

You can also use @android:style/Theme.Holo directly in AndroidManifest.xml if you do not want any customization at all.

Use Theme.AppCompat.Holo if API version below 11




回答3:


The default theme for App is implement in Resources.java!

    /**
 * Returns the most appropriate default theme for the specified target SDK version.
 * <ul>
 * <li>Below API 11: Gingerbread
 * <li>APIs 11 thru 14: Holo
 * <li>APIs 14 thru XX: Device default dark
 * <li>API XX and above: Device default light with dark action bar
 * </ul>
 *
 * @param curTheme The current theme, or 0 if not specified.
 * @param targetSdkVersion The target SDK version.
 * @return A theme resource identifier
 * @hide
 */
public static int selectDefaultTheme(int curTheme, int targetSdkVersion) {
    return selectSystemTheme(curTheme, targetSdkVersion,
            com.android.internal.R.style.Theme,
            com.android.internal.R.style.Theme_Holo,
            com.android.internal.R.style.Theme_DeviceDefault,
            com.android.internal.R.style.Theme_DeviceDefault_Light_DarkActionBar);
}
/** @hide */
public static int selectSystemTheme(int curTheme, int targetSdkVersion, int orig, int holo,
        int dark, int deviceDefault) {
    if (curTheme != 0) {
        return curTheme;
    }
    if (targetSdkVersion < Build.VERSION_CODES.HONEYCOMB) {
        return orig;
    }
    if (targetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        return holo;
    }
    if (targetSdkVersion < Build.VERSION_CODES.CUR_DEVELOPMENT) {
        return dark;
    }
    return deviceDefault;
}

It varies depending on the API level, so you'd better to define your own AppTheme in AndroidManifest.xml to assure Theme in all API level devices.

Pls refer previous answer.



来源:https://stackoverflow.com/questions/27277050/android-default-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!