public class MainActivity extends AppCompatActivity
- In the class where you need to hide the navigation bar, replace BaseActivity with AppCompatActivity
public class MainActivity extends BaseActivity
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import java.util.ArrayList;
import java.util.Map;
public class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideNavigationBar();
closeBar();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus){
hideNavigationBar();
}
}
public void hideNavigationBar() {
int uiFlags =
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
;
if( android.os.Build.VERSION.SDK_INT >= 19 ){
uiFlags |= 0x00001000;
} else {
uiFlags |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
}
getWindow().getDecorView().setSystemUiVisibility(uiFlags);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null){
actionBar.hide();
}
}
private void closeBar() {
try {
String command;
command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib service call activity 42 s16 com.android.systemui";
ArrayList<String> envlist = new ArrayList<String>();
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
envlist.add(envName + "=" + env.get(envName));
}
String[] envp = envlist.toArray(new String[0]);
Process proc = Runtime.getRuntime().exec(
new String[] {
"su", "-c", command }, envp);
proc.waitFor();
} catch (Exception ex) {
}
}
}