为什么单击弹出菜单时导航栏出现在全屏应用程序中 [英] Why navigation bar is appearing in fullscreen apps when clicked on popup menu

查看:154
本文介绍了为什么单击弹出菜单时导航栏出现在全屏应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全屏应用程序:

I have a fullscreen app:

MainActivity.java:

public class MainActivity extends AppCompatActivity {

@TargetApi(Build.VERSION_CODES.KITKAT)
private void removeControlBar(){
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(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
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
@Override
public void onResume(){
    super.onResume();
    removeControlBar();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="test.behy.android.test">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

它是全屏的,但是当我点击弹出菜单时,会出现导航栏(包括家庭,后卫的栏)!

it is fullscreen, but when I tap the popup menu the Navigation bar (bar including home, back) is appeared!

问题:

  • 为什么会这样?
  • 我该如何解决(避免出现导航栏)?

(我试图删除标题栏并添加带有弹出菜单的ImageButton,但这是完全一样的!) 感谢您的帮助!

(I tried to remove titlebar and add an ImageButton with popup menu but it was exactly the same!) thanks for help!

推荐答案

您正试图通过在onresume方法中调用粘性沉浸来管理它.这意味着状态一旦更改,在下一次活动恢复之前将不会恢复.

You are trying to manage the sticky immersion by calling it in your onresume method. This means once the state has been changed it will not be reinstated until the activity next resumes.

摆脱这个private void removeControlBar()

您需要通过Windows onfocuschanged方法对其进行管理.

You need to manage it via the windows onfocuschanged method.

通过这种方式可以处理警报,并且在处理弹出窗口时导航栏等不会返回视图.

This way alerts can be attended to and the nav bars etc will not return to the view when dealing with the pop ups.

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        decorView.setSystemUiVisibility(
            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
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}

文档使用粘性浸入和详细说明此处.

这篇关于为什么单击弹出菜单时导航栏出现在全屏应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆