8

How do I programatically dim the system bar in Android 3.0 (Honeycomb)?

N West
  • 6,768
  • 25
  • 40
Fredrik Hedberg
  • 147
  • 2
  • 8

2 Answers2

13

Try using the following code:

View v = findViewById(R.id.myview);
v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
Denvar
  • 202
  • 1
  • 4
  • 8
  • Is there a way to do this via XML? The reason I wish to do so is to change the functionality of existing compiled apps with only resource editing. – Jon Willis Sep 01 '11 at 21:19
  • 1
    i have tried with the view that i set in contentview. but it's not working. any idea? – gypsicoder Oct 26 '11 at 10:16
  • 1
    This should do the trick: "getWindow().getDecorView().setSystemUiVisibility( View.STATUS_BAR_HIDDEN )" – Marchy Oct 29 '12 at 19:43
  • 1
    Since API 14 getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LOW_PROFILE ); is the prefered – RMalke Jan 12 '13 at 19:01
1

you can dim it using SYSTEM_UI_FLAG_LOW_PROFILE but it will appear when user touch the bar. But you can disable it except home.

add this in manifest.

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

inside onCreate()

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_home);
    View v = findViewById(R.id.home_view);
    v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

where home_view is the parent view of xml file.

 @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
            return false;
        }

 public void onWindowFocusChanged(boolean hasFocus)
     {
             try
             {
                if(!hasFocus)
                {
                     Object service  = getSystemService("statusbar");
                     Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
                     Method collapse = statusbarManager.getMethod("collapse");
                     collapse .setAccessible(true);
                     collapse .invoke(service);
                }
             }
             catch(Exception ex)
             {
             }
     }

you can't capture the home event, the only thing is you can do is to give your application home category and let the user choose.

 <category android:name="android.intent.category.HOME" />
PiyushMishra
  • 5,743
  • 6
  • 37
  • 57
  • http://stackoverflow.com/questions/14801928/is-it-possible-to-hide-the-system-bar/15652646#15652646 – Murilo May 14 '14 at 20:13