显示弹出菜单时如何保持全屏?

时间:2016-12-02 04:20:08

标签: android fullscreen statusbar navigationbar popupmenu

我在平板电脑上运行我的应用程序,该应用程序同时具有状态栏(位于屏幕顶部)和导航栏(位于屏幕底部)。 我使用此代码制作function getCorporateService(id){ // get data and parsing to column $.get("{{ url('salesorder/service')}}/"+id, function(data){ console.log(id); console.log(data); $.each(data, function (index, element){ $br = "<tr id='item'>"; $br += "<td> <input class='input-small' type='text' id='order_identifier' name='order_identifier[]' readonly></td>"; $br += "<td><input class='input-small' type='text' id='service_name["+id+"]' name='service_name[]' value='"+element.service_name+"' readonly>" +"<input class='input-small' type='hidden' id='service_id["+id+"]' name='service_id[]' value='"+element.id+"' readonly></td>"; $br += "<td><select id='order_type["+id+"]' name='order_type[]'> <option> - </option> <option value='add'>Add</option> <option value='change'>Change</option> <option value='cancel'>Cancel</option> </select></td>"; $br += "<td><input class='input-small' type='text' id='select_plan["+id+"]' name='select_plan[]'></td>"; $br += "<td><input class='input-mini' type='text' id='qty["+id+"]' name='qty[]' value='1' onChange='getTotalPrice("+id+")'></td>"; $br += "<td><input class='input-small' type='text' id='unit_price["+id+"]' name='unit_price[]' onChange='getTotalPrice("+id+")'></td>"; $br += "<td><input class='input-small' type='text' id='total_price["+id+"]' name='total_price[]' onChange='getTotalPrice("+id+")'></td>"; $br += "<td><textarea class='input-small' id='notes["+id+"]' name='note[]'></textarea></td>"; $br += "</tr>"; $(".corporatesvc").append($br); }); }); } 全屏

Activity

然后,当我触摸 public void hideNavigationBar() { final View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(setSystemUiVisibility()); } public static int setSystemUiVisibility() { return 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; } 时,我想显示Button。问题是:显示PopupMenu时,状态栏和导航栏会显示

我尝试添加此行:

PopupMenu

适用于状态栏。但是,当显示 PopupMenu 时,导航栏仍会显示

展示 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 时如何保持全屏?

编辑:以下是我展示PopupMenu的代码:

PopupMenu

3 个答案:

答案 0 :(得分:0)

TOP你可以试试这段代码希望这可以帮到你..

 @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}

答案 1 :(得分:0)

当弹出菜单消失时,只需呼叫您的hideNavigationBar()。您可以在主要活动中执行以下操作(kotlin中的代码):

override fun onWindowFocusChanged(hasFocus: Boolean) {
    if (hasFocus) hideNavigationBar()
    super.onWindowFocusChanged(hasFocus)
}

答案 2 :(得分:0)

我无法完成确切的行为,但在上下文菜单关闭后立即使活动全屏显示,对于我的用例来说效果很好。

override fun onContextMenuClosed(menu: Menu) {
    super.onContextMenuClosed(menu)
    fullScreen()
}

这是我使用的全屏方式:

fun Activity.fullScreen() {
    if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
        val v = this.window.decorView
        v.systemUiVisibility = View.GONE
    } else if(Build.VERSION.SDK_INT >= 19) {
        //for new api versions.
        val decorView = window.decorView
        val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        //original code from stackOverFlow: View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        decorView.systemUiVisibility = uiOptions
    }
}