在Android编程中如何在自己的Launcher中,让屏幕上方的Statusbar(系统状态栏)设置为透明

pof 发布于 2011/12/21 17:51
阅读 3K+
收藏 0

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

如何在自己的Launcher中,让屏幕上方的Statusbar(系统状态栏)设置为透明,貌似Android有一些API在SDK中没有开放,比如StatusBarManager
加载中
0
K
Kevin_Gan
在SystemUI里面改。
0
myzcxhh
myzcxhh

请在你的Activity中继承BaseActivity

代码如下:

import android.annotation.TargetApi;  import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.view.Window; import android.view.WindowManager;  public class BaseActivity extends Activity {  protected SystemBarTintManager mTintManager;   protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);  }  mTintManager = new SystemBarTintManager(this);  } @TargetApi(19) protected void setTranslucentStatus(boolean on) {
        Window win = getWindow();  WindowManager.LayoutParams winParams = win.getAttributes();  final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;  if (on) {
            winParams.flags |= bits;  } else {
            winParams.flags &= ~bits;  }
        win.setAttributes(winParams);  }

}

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部