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

限于喜欢 提交于 2019-12-17 12:11:50

问题


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


回答1:


Try using the following code:

View v = findViewById(R.id.myview);
v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);



回答2:


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" />


来源:https://stackoverflow.com/questions/5883789/how-do-i-dim-the-system-bar-in-android-3-0-honeycomb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!