Unable To Hide Navigation Bar during AlertDialog/LoginDialog
Solution 1
try this code
@Override
public void show() {
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
super.show();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
this.getWindow().getDecorView().setSystemUiVisibility(uiOptions);
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}
Solution 2
Maybe this can help you? https://stackoverflow.com/a/23435922/3464293
Smthng like this?
View decorView = getActivity().getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Update: (source: https://stackoverflow.com/a/2844648/3464293)
In your LoginDialog.java add this method:
@Override
public void onStart() {
super.onStart();
Window window = getDialog().getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
window.requestWindowFeature(Window.FEATURE_NO_TITLE);
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
window.getDecorView().setSystemUiVisibility(uiOptions);
}
and try then. Remove previous updates.
user3585761
Updated on June 26, 2022Comments
-
user3585761 almost 2 years
I'm attempting to hide the navigation bar globally through my app running Android 4.2.2
I have managed to use the following (admitadly hackish) method of implementing:
getWindow().getDecorView().setSystemUiVisibility(8);
Which successfully removes the Navigation bar (the fact it is hackish is perfectly fine - this is for a kiosk so it will only be installed on a limited number of devices)
Now I'm attempting to remove the navigation bar in places other than my MainActivity - such as when it reappears during an AlertDialog/LoginDialog.
I'm attempting to use:
public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(),R.style.HoloDarkDialog)); LayoutInflater inflater = getActivity().getLayoutInflater(); variables = SingletonVariables.getInstance(); view = inflater.inflate(R.layout.login, null); EditText userEditText = (EditText) view.findViewById(R.id.loginUserIdEditText); getWindow().getDecorView().setSystemUiVisibility(8);
However this result in the error:
The method getWindow() is undefined for the type LoginDialog
Does anyone know of a way this might be avoided?
Edit: (additional requested source code)
// Function to handle show dialog public void showLogin(View view, String whichActivity) { pd = new ProgressDialog(this.getApplicationContext()); pd.setMessage("Logging in, Please wait...."); LoginDialog logindialog = new LoginDialog(); logindialog.setWhichActivity(whichActivity); logindialog.show(getFragmentManager(), "MyLogin"); }
-
user3585761 about 10 yearsI tried it... the error went away - however the navigation bar is still shown when the dialog appears
-
user3585761 about 10 yearsI tried it. It results in: "The constructor Dialog(LoginDialog) is undefined"
-
Nexowski about 10 yearscould you post your code where youre building your login dialog and doing the .show() method? I'm not sure what are you doing now. Dialog(this) takes Context as argument. For example this.getApplicationContext()
-
Nexowski about 10 yearsedited answer, try it. You pasted me the class, but where do you instantiate your LoginDialog and use LoginDialog.show()? I'm not sure if my update will run.
-
Nexowski about 10 yearsOk, so you need to try it in the place before you do LoginDialog.show(). Where do you instantiate your LoginDialog? Like LoginDialog dialog = new LoginDialog();?
-
user3585761 about 10 yearspublic void showLogin(View view, String whichActivity) { (shown above in a recent edit)
-
user3585761 about 10 yearsUsing your most recent answer verbatim results in the error: The method getWindow() is undefined for the type LoginDialog In order to avoid this I simply added getActivity() here: Window dialog_window = logindialog.getActivity().getWindow(); dialog_window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); logindialog.setWhichActivity(whichActivity); however it causes a force close NPE on the line Window dialog_window = logindialog.getActivity().getWindow(); Any suggestions?
-
Nexowski about 10 yearsOk, for dialogfragment (your LoginDialog extends the Dialogfragment) you need to do a little different thing. I will update my answer in few minutes.
-
Nexowski about 10 yearsIt works? If yes, then maybe accept the answer, if not then lets try further :)
-
user3585761 about 10 yearsI tried your most recent suggestion - the navigation bar still appears when the dialog/edittext appears: pastebin.com/RYR5Gwzv
-
Nexowski about 10 yearsI've added the requestWindowFeature, try it maybe.