简体   繁体   English

android:如何在全屏对话框中隐藏底部按钮

[英]android: how to hide bottom buttons on dialog fullscreen

I'm trying to hide navigation buttons when a dialog is shown fullscreen.当对话框全屏显示时,我试图隐藏导航按钮。 I've manage to do it following this example: Android fullscreen dialog我已经按照这个例子设法做到了: Android fullscreen dialog

however, whenever i touch a button they appear again.但是,每当我触摸一个按钮时,它们就会再次出现。

is there any way to hide them properly?有什么办法可以正确隐藏它们吗?

要隐藏的导航按钮

thanks谢谢

The following snippet hides the navigation bar and status bar:以下代码段隐藏了导航栏和状态栏:

window.decorView.apply {
    // Hide both the navigation bar and the status bar.
    // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
    // a general rule, you should design your app to hide the status bar whenever you
    // hide the navigation bar.
    systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN
}

From https://developer.android.com/training/system-ui/navigation来自https://developer.android.com/training/system-ui/navigation

Nonetheless for your case you need two things to happen.尽管如此,对于您的情况,您需要做两件事。

  • First, set windowFullScreen to true to allow the dialog to paint every pixel in the screen.首先,将windowFullScreen设置为 true 以允许对话框绘制屏幕中的每个像素。 (ie Use any FullScreen theme). (即使用任何全屏主题)。

  • Then, on you dialog, set the systemUiVisibility to View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION .然后,在您的对话框中,将systemUiVisibility设置为View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

This will stop the navigationBar from ever showing until you reset the flags or dismiss the dialog.这将阻止导航栏显示,直到您重置标志或关闭对话框。

The complete snippet:完整的片段:

class SomeActivity {

    fun showDialog() {
        FullScrenDialog()
            .apply {
                setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_NoTitleBar_Fullscreen)
            }
            .show(supportFragmentManager, "TAG")
    }

}


class FullScrenDialog : DialogFragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        dialog.window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        return inflater.inflate(R.layout.dialog, container)
    }

}

Please try below code for dialog:请尝试以下对话框代码:

final Dialog dialog = new Dialog(this);
        dialog.setCancelable(false);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.getWindow().setGravity(Gravity.CENTER);
        dialog.setContentView(R.layout.dialog_logout);
        Window window = dialog.getWindow();
        window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
        window.getDecorView().setSystemUiVisibility(uiOptions);
        dialog.show();

Output is:输出是:

在此处输入图像描述

I hope it works for you.我希望这个对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM