2012-03-25 134 views
25

我需要我的應用程序顯示爲全屏。現在我知道了如何使用全屏自定義主題

android:theme=」@android:style/Theme.NoTitleBar.Fullscreen" 

但是,我有我自己的主題叫「CodeFont」添加此功能到應用程序標籤在Mainfest,我不能在同一個應用程序中使用的兩個主題。我如何在我的資源文件中將此功能添加到我自己的樣式標記中?沒有像android:style標籤這樣的東西。

回答

63

使用默認主題,像這樣

Fullscreen

<style name="generalnotitle" parent="general"> 
    <item name="android:windowFullscreen">true</item> 
</style> 

窗口窗口NoTitle

<style name="generalnotitle" parent="general"> 
    <item name="android:windowNoTitle">true</item> 
</style> 
+1

此不做全屏。你需要 true robsf 2012-12-07 20:18:58

+4

如果有人想知道,把它放在'res/values/styles.xml'中。 – v42 2013-12-13 19:06:03

+0

當我使用windowFullscreen設置爲false時,它做了與我所期望的相反的操作。它使我的對話完全全屏。而沒有自定義主題,我的對話框只是巨大的,實際上佔用整個屏幕(寬度和高度)不成功。這是爲什麼? – RTF 2014-02-24 23:29:52

1

創建自定義的主題,你可以通過使用要求在代碼中的一些特點和標誌(舉例):

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.some_layout); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
7

使用父屬性創建您的自定義主題,從通用Android主題繼承NoTitleBar.Fullscreen屬性。

值/ styles.xml

<resources> 
    <style name="CodeFont" parent="android:Theme.NoTitleBar.Fullscreen"> 
     <item name="android:windowNoTitle">true</item> 
     ... 
    </style> 
</resources> 

AndroidManifest.xml中

<activity 
    android:name=".MainActivity" 
    android:theme="@style/CodeFont"> 
     ... 
</activity> 
6

在style.xml添加

<item name="android:windowFullscreen">true</item> 

你的主題。示例:

<style name="CodeFont" parent="android:Theme.Light"> 
    <item name="android:windowFullscreen">true</item> 
</style> 
0

在應用程序樣式中設置主題適用於我的React Native應用程序。只需在android/app/src/main/res/values/styles.xml

<resources> 
    <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar.Fullscreen"></style> 
</resources> 

而且在android/app/src/main/AndroidManifest.xml鏈接到這個主題:

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

Reference