Android default theme

前端 未结 3 981
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-12 21:53

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 t

相关标签:
3条回答
  • 2021-02-12 21:57

    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.

    0 讨论(0)
  • 2021-02-12 22:08

    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.

    0 讨论(0)
  • 2021-02-12 22:19

    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

    0 讨论(0)
提交回复
热议问题