简体   繁体   中英

Android - How to turn off home/back/recent apps buttons light on Google Pixel 2

I want to turn off keys(home, back, recent apps) lights on the activity. Here is my code.

Settings.System.putInt(getApplicationContext().getContentResolver(), "button_key_light", 0);

It works well on Samsung phone, but it doesn't work on other devices such as Google Pixel 2.

Please help me.

You can try this-:

@Override  
public boolean onKeyDown(int keyCode, KeyEvent event)  
{  
    if(keyCode == KeyEvent.KEYCODE_BACK)  
    {  
        Log.d("Test", "Back button pressed!");  
    }  
    else if(keyCode == KeyEvent.KEYCODE_HOME)  
    {  
        Log.d("Test", "Home button pressed!");  
    }  
    return super.onKeyDown(keyCode, event);  
}  

I have solved this problem by using Immersive Full-Screen Mode.

https://github.com/superdev0714/DisableHome.java/blob/master/DisableHome.java

I solved myself. It works well.

private void disableHomebutton() {
    final int uiOptions = 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 // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE;

    mainView.setSystemUiVisibility(uiOptions);

    mainView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            mainView.setSystemUiVisibility(uiOptions);
        }
    });


    mHomeKeyLocker.lock(this);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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