android6.0 状态栏添加图标 举例Location
16lz
2021-01-23
增加状态图标步骤如下:
:1: 将图片放在 \frameworks\base\packages\SystemUI\res\drawable-hdpi(实际情况自己选择)
:2:\frameworks\base\core\res\res\values config.xml
添加
3:\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone PhoneStatusBarPolicy.java 添加如下(注意名字要与 config.xml中定义的一致)
mService.setIcon(“eyeball”, R.drawable.stat_sys_eyeball, 0,null);
mService.setIconVisibility(“eyeball”, true);
这只是简单的添加一个图标,没有对他进行控制
下面举个我在工作当中实现的一个例子——添加Location图标
添加图片和item我就不贴出来了
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/frameworks/basindex c0b6fa5..5140280 100644--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java@@ -189,7 +189,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener, HeadsUpManager.OnHeadsUpChangedListener { static final String TAG = "PhoneStatusBar";- public static final boolean DEBUG = BaseStatusBar.DEBUG;+ public static final boolean DEBUG = true;//BaseStatusBar.DEBUG; public static final boolean SPEW = false; public static final boolean DUMPTRUCK = true; // extra dumpsys info public static final boolean DEBUG_GESTURES = false;@@ -624,7 +624,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, // Lastly, call to the icon policy to install/update all the icons. mIconPolicy = new PhoneStatusBarPolicy(mContext, mCastController, mHotspotController,- mUserInfoController, mBluetoothController);+ mUserInfoController, mBluetoothController,mLocationController); mIconPolicy.setCurrentUserSetup(mUserSetup);/statusbar/phone/PhoneStatusBarPolicy.javadiff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/frameworindex fa9c4bb..7558d76 100644--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java@@ -45,6 +45,8 @@ import com.android.systemui.statusbar.policy.BluetoothController.Callback; import com.android.systemui.statusbar.policy.CastController; import com.android.systemui.statusbar.policy.CastController.CastDevice; import com.android.systemui.statusbar.policy.HotspotController;+import com.android.systemui.statusbar.policy.LocationController;+import com.android.systemui.statusbar.policy.LocationController.LocationSettingsChangeCallback; import com.android.systemui.statusbar.policy.UserInfoController;-public class PhoneStatusBarPolicy implements Callback {+public class PhoneStatusBarPolicy implements Callback,LocationSettingsChangeCallback { private static final String TAG = "PhoneStatusBarPolicy"; public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot,- UserInfoController userInfoController, BluetoothController bluetooth) {+ UserInfoController userInfoController, BluetoothController bluetooth,LocationController locationController) { mContext = context; mCast = cast; mHotspot = hotspot; mBluetooth = bluetooth; mBluetooth.addStateChangedCallback(this);+ mLocationController = locationController;+ mLocationController.addSettingsChangedCallback(this); @Override+ public void onLocationSettingsChanged(boolean locationEnabled){+ updateLocation();+ }+ + private LocationController mLocationController;+ private void updateLocation(){+ boolean bluetoothEnabled = false;+ if (mLocationController != null) {+ bluetoothEnabled = mLocationController.isLocationEnabled();+ }+ mService.setIcon("location",R.drawable.stat_sys_location,0,null);+ mService.setIconVisibility("location",bluetoothEnabled);+ }+
这的LocationContorller是SystemUI中就已经定义的了如自己添加的没有控制类,要自己根据实际情况添加。
更多相关文章
- android上传图片和参数(属性)到服务器
- android使用自定义属性
- Android 自定义ToneGenerator
- 关于android的animation的xml定义中的android:interpolator属性
- android自定义标题栏。。。。。。。
- Android多点触控---Matrix图片随意的放大缩小,拖动
- Android图片轮播控件---com.youth.banner.Banner
- Android上传图片到服务器,android-async-http上传图片到服务器
- Android Interface Definition Language (AIDL) android接口定义