前言
欢迎大家我分享和推荐好用的代码段~~
声明
欢迎转载,但请保留文章原始出处:
优快云:http://www.youkuaiyun.com
雨季o莫忧离:http://blog.youkuaiyun.com/luckkof
正文
状态栏默认背景为黑色。要求修改为:Launcher界面状态栏为透明,其他界面为黑色。
1. 请添加半透明的图片资源,例如:statusbar_background.9.png,到路径alps\frameworks\base\packages\SystemUI\res\drawable-hdpi 下
2. 如果是gemini工程请修改gemini_status_bar.xml,反之修改status_bar.xml,把其中的android:background="@drawable/status_bar_background 修改成android:background="@drawable/statusbar_background
3. 修改PhoneWindowManager.java的beginLayoutLw方法,如下(修改代码用//mtk added标记):
<span style="font-size:10px;">public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotation) {
...... mUnrestrictedScreenLeft = mUnrestrictedScreenTop = 0;
if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()) {
// If the status bar is currently requested to be visible,
// and not in the process of animating on or off, then
// we can tell the app that it is covered by it.
// mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; //mtk added 把这行注释掉
}
}
}</span>
4. 请在PhoneStatusBar.java的makeStatusBarView(Context context)方法中注册一个BroadcastReceiver接收自定义的intent,监控是否在Launcher界面。
5. 请在Launcher.java添加onWindowFocusChanged (boolean hasWindowFocus)方法,如果此方法已有,请跳过此步骤。
6. 请修改Launcher.java的onWindowFocusChanged (boolean hasWindowFocus)方法:如果hasWindowFocus为true且!isAllAppsVisible()为true,发送设置状态栏背景为透明的intent,PhoneStatusBar的BroadcastReceiver接收到这个intent,调用mStatusBarView.setBackgroundResource(R.drawable.xxxx)将背景设置为半透明背景;否则,发送设置状态栏背景为黑色的intent,PhoneStatusBar的BroadcastReceiver接收到这个intent,调用mStatusBarView.setBackgroundResource(R.drawable.xxxx)将背景设置为黑色背景。
7. 请在Launcher.java的showAllApps(boolean animated) 方法中发送设置状态栏背景为黑色的intent,PhoneStatusBar的BroadcastReceiver接收到这个intent,调用mStatusBarView.setBackgroundResource(R.drawable.xxxx)将背景设置为黑色背景。
8. 请在Launcher.java的showWorkspace(boolean animated)方法中发送设置状态栏背景为透明的intent,PhoneStatusBar的BroadcastReceiver接收到这个intent,调用mStatusBarView.setBackgroundResource(R.drawable.xxxx)将背景设置为半透明背景。