我希望我的应用程序显示为全屏。现在我知道如何使用 Mainfest 中的应用程序标记添加此功能。
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen"
然而,我有自己的主题叫做"CodeFont",而且我无法在同一个应用程序中使用两个主题。我该如何将此功能添加到我的资源文件中的自定义样式标签中?并没有像android:style这样的东西。
我希望我的应用程序显示为全屏。现在我知道如何使用 Mainfest 中的应用程序标记添加此功能。
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen"
然而,我有自己的主题叫做"CodeFont",而且我无法在同一个应用程序中使用两个主题。我该如何将此功能添加到我的资源文件中的自定义样式标签中?并没有像android:style这样的东西。
通过使用默认主题来创建您的自定义主题,就像这样
窗口带有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>
通过使用parent
属性创建自定义主题,从通用的Android主题继承NoTitleBar.Fullscreen
属性。
values/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>
<item name="android:windowFullscreen">true</item>
适用于您的主题。例如:
<style name="CodeFont" parent="android:Theme.Light">
<item name="android:windowFullscreen">true</item>
</style>
你可以通过在代码中使用(例如)来请求一些功能和标志:
@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);
在我的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">
res/values/styles.xml
里。 - v42