2014-12-03 131 views
12

我正在製作一個Android應用程序,但我正在考慮主題..Android默認主題

如果我沒有聲明我的Android應用程序的主題將使用哪個主題? 我在哪裏可以找到這些信息? 使用一個和其他的標準是什麼?

我在想,如果我想定製我的所有應用程序,我必須擴展一個主題和自定義所有項目,我想要自定義。

如果它假設其中一個爲默認設置會怎麼樣?天氣我必須再次定製它?我如何知道什麼是默認的?

+0

看看這個http://stackoverflow.com/questions/9832114/how-to-use-device-default-theme-for-app – Antrromet 2014-12-03 16:46:18

回答

14

默認主題因API級別而異(爲了與常規UI保持一致)。

在API < 10的主題是一組樣式(如在下面的鏈接)被稱爲Theme,該API 10的上方,默認主題是Theme_Holo,現在,開始與API 21,默認的主題已成爲Theme.Material

大多數這些樣式可通過android.support庫獲得。

PS: AFAIK輕的主題一直是默認的主題。

+0

如果我想爲所有人使用Theme_Holo,包括<10? – user1851366 2014-12-03 16:53:38

+1

然後,你需要看看一個名爲「HoloEverywhere」的東西,現在'AppCompat'已經沒用了...... – shkschneider 2014-12-03 16:56:13

+1

@ user1851366要在最低版本的版本上使用Holo或者甚至材質主題,你應該使用android支持庫v7。您可以使用AppCompat(提供Material Design Action Bar等)以及CardView或RecyclerView等佈局元素。它在Android官方網站上有很好的報道。 – fragon 2014-12-03 17:47:37

3

最好自己定義一個默認主題,而不是依靠android來選擇默認主題。這是因爲不同版本的Android 可能具有完全不同的默認主題,並可能會搞亂你的佈局。

可以在res/values文件夾中AndroidManifest.xml

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

宣佈主題爲您的應用程序。然後,您可以編輯/添加文件themes.xml,並添加類似以下內容:

<?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> 

您可以編輯您的主題parent您想要的任何東西...

您還可以使用@android:style/Theme.Holo直接在AndroidManifest.xml,如果你根本不想任何定製。

使用Theme.AppCompat.Holo如果跌破11

0

API版本的應用程序的默認主題是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; 
} 

這取決於API級別,所以你最好定義自己的AppTheme在AndroidManifest.xml中,以確保在所有的API級設備主題。

請參考先前的答案。