Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Disabling Android Home Button (It's not 100% there, but using immersive on KitKat should make it work much better)
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.view.WindowManager;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Handler;
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState == null) {
.add(, new PlaceholderFragment())
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == {
return true;
return super.onOptionsItemSelected(item);
* A placeholder fragment containing a simple view.
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View decorView = inflater.inflate(R.layout.fragment_main, container, false);
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
(new View.OnSystemUiVisibilityChangeListener() {
public void onSystemUiVisibilityChange(int visibility) {
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
getActivity().runOnUiThread(new Runnable() {
public void run() {
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActivity().getActionBar();
timer.scheduleAtFixedRate(task, 0, 1);
return decorView;

nice way... :-)

Zhambul commented May 8, 2015

It's not working on 5.x android


is it working for android lollipop ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.