androidandroid-activitysoftkeys

android- hide softkey (permanently) while changing activity


my smartphone has softkeys which i want to hide permanently in my APP. i use that function below to hide the softkeys.

public void setFullscreen(boolean fullscreen) {
        WindowManager.LayoutParams attrs = getWindow().getAttributes();
        if (fullscreen) {
            attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
            attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
        }
        else {
            attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
            attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
            attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
        }
        getWindow().setAttributes(attrs);
        View v = this.getWindow().getDecorView();
        v.setSystemUiVisibility(View.GONE);
    }

i call that function in all activitys in onCreate, before protected void onCreate(Bundle savedInstanceState) like so..

    @Override
protected void onCreate(Bundle savedInstanceState)
{
    setFullscreen(true);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myLayout);
}

the problem: i am changing the activity and the softkeys appear and hide again. how do i prevent them from appearing?

i also use "stateHidden" in the manifest for all activitys

        <activity
        android:name=".myActivity"
        android:windowSoftInputMode="stateHidden" />

hope you can help me out... big thanks! :)


Solution

  • finally! here is one solution. thanks!

    private void hideSystemUI() {
        getWindow().getDecorView().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);
    }
    
    
    
    public void setFullscreen(boolean fullscreen) {
    
        WindowManager.LayoutParams attrs = getWindow().getAttributes();
        if (fullscreen) {
            attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
            attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
            attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
            attrs.flags |= WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
    
        }
        else {
            attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
            attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
            attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
        }
        getWindow().setAttributes(attrs);
        hideSystemUI();
    }