Trilok
Trilok

Reputation: 53

how to hide android softkeys

In my android app I hide soft keys bar using this:

View decorView = getWindow().getDecorView();

int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

decorView.setSystemUiVisibility(uiOptions);

But the problem is when some message box or toast display then softkeys display again. I want to hide soft keys when any message box or toast displaying.

Is it possible.. how can i do this.

Upvotes: 1

Views: 385

Answers (1)

RobCo
RobCo

Reputation: 6495

Messages like dialogs, intent chooser, soft keyboard and toasts use a different Window than your main application window.
These extra Windows can change your SystemUiVisibility and Window flags as they appear and disappear.

What I found to work in most cases is to setup your flags in onWindowFocusChanged in the Activity class:

public void onWindowFocusChanged(boolean hasFocus) {
    if(hasFocus) {
        View decorView = getWindow().getDecorView();

        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

        decorView.setSystemUiVisibility(uiOptions);
    }
}

You then no longer need this code in onCreate, as window focus is also gained at activity creation.

Upvotes: 1

Related Questions