我想知道如何应用全屏主题(没有标题栏+没有动作栏)到一个活动。我使用的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

您可以遵循以下步骤:-

AndoridMenifest.xml

<activity
            android:name=".ui.FullImageActivity"
            android:label="@string/title_activity_main"
            android:screenOrientation="landscape"
            android:theme="@style/DialogTheme">
        </activity>

Style.xml

<style name="DialogTheme" parent="android:Theme.Dialog">

    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>

   <!-- No backgrounds, titles or window float -->
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

FullImageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    setContentView(R.layout.image_view);
     }

希望对大家有所帮助,谢谢!!

requestWindowFeature(Window.FEATURE_NO_TITLE);

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

我希望这对你有帮助;)

<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,您将能够隐藏标题以及操作栏。

当你使用主题。在你的应用程序中,你可以通过添加下面的代码样式来使用FullScreenTheme。

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

在你的清单里也要提到。

<activity
   android:name=".activities.FullViewActivity"
   android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen" 
/>

根据@nebyan的回答,我发现操作栏仍然没有隐藏。

下面的代码为我工作:

<style name="AppFullScreenTheme" parent="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>

当然,不要忘记编辑你的AndroidManifest文件。

<activity
    android:name="YOUR_ACTIVITY_NAME"
    android:theme="@style/AppFullScreenTheme" 
/>

删除AppCompat中的标题栏:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
    }
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //to remove "information bar" above the action bar
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //to remove the action bar (title bar)
    getSupportActionBar().hide();
}
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>

就这个?

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen">
    <item name="android:windowFullscreen">true</item>
</style>

此主题仅适用于API 21(包含)之后。并使状态栏和导航栏都透明。

<style name="TransparentAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  <item name="windowActionBar">false</item>
  <item name="windowNoTitle">true</item>
  <item name="android:statusBarColor">@android:color/transparent</item>
  <item name="android:windowBackground">@android:color/transparent</item>
  <item name="android:navigationBarColor">@android:color/transparent</item>
  <item name="android:windowIsTranslucent">true</item>
  <item name="android:windowContentOverlay">@null</item>
</style>

它应该是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>

隐藏状态栏和操作栏,使你的活动全屏使用以下代码在你的活动的onResume()或onWindowFocusChanged()方法:

@Override
protected void onResume() {
    super.onResume();
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN);
}

你可在以下连结找到更多资料:

https://developer.android.com/training/system-ui/immersive#EnableFullscreen 全屏,没有导航和状态栏 如何隐藏Android手机上的软键栏?

注意:使用这个线程中提供的xml解决方案,我只能隐藏状态栏,而不能隐藏导航栏。

你可以尝试以下方法:

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