自定义主题全屏

pan*_*nda 30 android android-theme android-styles

我需要我的应用程序显示为全屏.现在我知道如何将此功能添加到Mainfest中的应用程序标签中

android:theme=”@android:style/Theme.NoTitleBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)

但是,我有自己的主题叫做"CodeFont",我不能在同一个应用程序中使用两个主题.如何在我的资源文件中将此功能添加到我自己的样式标记中?没有像android:style标签这样的东西.

Raj*_*ddy 71

使用默认主题创建自定义主题,如下所示

窗口 Fullscreen

<style name="generalnotitle" parent="general">
    <item name="android:windowFullscreen">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

窗口 NoTitle

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

  • 万一有人想知道,把它放在`res/values/styles.xml`上. (5认同)
  • 这不会全屏显示。您需要&lt;item name =“ android:windowFullscreen”&gt;为真&lt;/ item&gt; (2认同)

小智 10

使用parent属性创建自定义主题,以从常规android主题继承NoTitleBar.Fullscreen属性.

价值观/ styles.xml

<resources> 
   <style name="CodeFont" parent="android:Theme.NoTitleBar.Fullscreen">
      <item name="android:windowNoTitle">true</item> 
      ...
   </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

<activity 
    android:name=".MainActivity" 
    android:theme="@style/CodeFont"> 
      ...
</activity>
Run Code Online (Sandbox Code Playgroud)


rob*_*bsf 6

在style.xml中添加

<item name="android:windowFullscreen">true</item>
Run Code Online (Sandbox Code Playgroud)

你的主题.例:

<style name="CodeFont" parent="android:Theme.Light">
     <item name="android:windowFullscreen">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)