手机访问 | 设为首页 | 加入收藏 | 网站地图

当前位置:电脑中国 > 编程 > 移动开发 >

android状态栏电量百分比控制

2017-04-26 15:01|来源:未知 |作者:dnzg |点击:
android状态栏电量百分比控制:原生google代码没有这个选项 要长按下拉框的设置小图标 打开界面调谐器 才能显示百分比控制,但是也不美观,下面就添加这个功能,直接上修改方法,锁屏界面同步 请看android锁屏界面电量百分比显示与主桌面同步
路径frameworks\base\core\java\android\provider\Settings.java
在这里加入静态变量

 

?
1
2
3
4
5
6
7
// add for battery
         /**
         * turn on/off the battery percentage show in status bar
         * @hide
         */
        public static final String BATTERY_PERCENTAGE = "battery_percentage";
// add end

路径frameworks\base\packages\SettingsProvider\src\com\android\providers\settings\DatabaseHelper.java

?
1
2
3
4
5
6
7
8
private void loadSecureSettings(SQLiteDatabase db) {
        SQLiteStatement stmt = null;
            ...........
            ...........
//add for battery
            loadSetting(stmt, Settings.Secure.BATTERY_PERCENTAGE,"true");
            ..........
            }

\frameworks\base\packages\SystemUI\res\layout\status_bar.xml加入布局

?
1
<textview android:id="@+id/battery_level" android:importantforaccessibility="noHideDescendants" android:layout_gravity="center_vertical" android:layout_height="wrap_content" android:layout_marginstart="@dimen/header_battery_margin_keyguard" android:layout_width="wrap_content" android:paddingend="@dimen/battery_level_padding_end" android:textcolor="#ffffff" android:textsize="@dimen/battery_level_text_size"></textview>

frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\PhoneStatusBar.java加载布局

?
1
2
3
4
5
6
7
BrightnessMirrorController mBrightnessMirrorController;
AccessibilityController mAccessibilityController;
/// M: Add extra tiles @{
private TextView mBatteryLevel;//add
//add HotKnot in quicksetting
HotKnotControllerImpl mHotKnotController;
//add AudioProfile in quicksetting
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
protected PhoneStatusBarView makeStatusBarView() {
        ........
           // Other icons
        mLocationController = new LocationControllerImpl(mContext,
        mHandlerThread.getLooper()); // will post a notification
        mBatteryController = new BatteryController(mContext);
        mBatteryController.addLabelView((TextView)mStatusBarWindow.
         findViewById(R.id.battery_level));//add for battery
        mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() {
            @Override
            public void onPowerSaveChanged() {
                mHandler.post(mCheckBarModes);
                if (mDozeServiceHost != null) {
 
                }
            }
}
(责任编辑:dnzg)