我想知道如何应用全屏主题(没有标题栏+没有动作栏)到一个活动。我使用的AppCompat库从支持包v7。

我已经尝试应用android:theme="@android:style/ theme . notitlebar。“全屏”到我的特定活动,但它崩溃了。我想是因为我的应用主题是这样的。

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

我也试过这个

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

它只隐藏标题栏,而不隐藏操作栏。 我目前的工作是隐藏的动作栏与

getSupportActionBar().hide();

当前回答

你的“变通”(隐藏actionBar自己)是正常的方式。但是谷歌建议当标题栏被隐藏时总是隐藏动作栏。看看这里:https://developer.android.com/training/system-ui/status.html

其他回答

在Android 4.0 (API级别14)版本之前和之后出现的问题。

从这里 我创造了自己的解决方案。

@SuppressLint("NewApi")
@Override
protected void onResume()
{
    super.onResume();

    if (Build.VERSION.SDK_INT < 16)
    {
        // Hide the status bar
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // Hide the action bar
        getSupportActionBar().hide();
    }
    else
    {
        // Hide the status bar
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
        / Hide the action bar
        getActionBar().hide();
    }
}

我在onResume()方法中编写这段代码,因为如果你退出应用程序,然后重新打开它,操作栏仍然是活动的!(这样问题就解决了)

我希望这对你有帮助;)

你的“变通”(隐藏actionBar自己)是正常的方式。但是谷歌建议当标题栏被隐藏时总是隐藏动作栏。看看这里:https://developer.android.com/training/system-ui/status.html

你可以尝试以下方法:

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowFullscreen">true</item>
</style>
<style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

在style.xml中使用上述xml,您将能够隐藏标题以及操作栏。

它应该是parent="@style/Theme.AppCompat.Light.NoActionBar"

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" 
parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>