日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 7.0 SystemUI 之启动和状态栏和导航栏简介

發布時間:2025/3/15 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 7.0 SystemUI 之启动和状态栏和导航栏简介 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android 7.0 SystemUI 之啟動和狀態欄和導航欄簡介

一、SystemUI 是什么

首先SystemUI 是一個系統應用,apk路徑位于/system/priv-app

源碼路徑位于:/framework/base/packages/SystemUI

它負責的功能如下:

  • 狀態欄信息的展示:比如電量信息,時間,wifi狀態等
  • 通知欄消息
  • 壁紙管理
  • 截圖功能
  • 近期任務欄顯示,比如長按home鍵顯示最近使用的app
  • 錄制屏幕功能
  • 截圖服務

以下是7.0 SystemUI 的代碼截圖


二、SystemUI 的啟動

SystemUI 是在SystemServer里的AMS實例的systemReady方法里調用startSystemUi方法啟動

SystemServer路徑:/base/services/java/com/android/server/SystemServer.java

mActivityManagerService.systemReady(new Runnable() {......static final void startSystemUi(Context context) {Intent intent = new Intent();intent.setComponent(new ComponentName("com.android.systemui","com.android.systemui.SystemUIService"));intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);//Slog.d(TAG, "Starting service: " + intent);context.startServiceAsUser(intent, UserHandle.SYSTEM);}......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

在這個方法里啟動一個SystemUIService服務.

public class SystemUIService extends Service {@Overridepublic void onCreate() {super.onCreate();((SystemUIApplication) getApplication()).startServicesIfNeeded();}......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在onCreate方法中會調用SystemUIApplication的startServicesIfNeeded方法,這個方法會調用 startServicesIfNeeded(SERVICES)方法啟動一系列服務(并不是真正的服務,都繼承自SystemUI),可以這么說SystemUI就是一個容器,里面裝有負責不同功能的模塊。

public class SystemUIApplication extends Application {......private final Class<?>[] SERVICES = new Class[] {com.android.systemui.tuner.TunerService.class,com.android.systemui.keyguard.KeyguardViewMediator.class,com.android.systemui.recents.Recents.class,com.android.systemui.volume.VolumeUI.class,Divider.class,com.android.systemui.statusbar.SystemBars.class,com.android.systemui.usb.StorageNotification.class,com.android.systemui.power.PowerUI.class,com.android.systemui.media.RingtonePlayer.class,com.android.systemui.keyboard.KeyboardUI.class,com.android.systemui.tv.pip.PipUI.class,com.android.systemui.shortcut.ShortcutKeyDispatcher.class};public void startServicesIfNeeded() {startServicesIfNeeded(SERVICES);}......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

startServicesIfNeeded方法會遍歷services這個數組,依次調用service的start方法啟動服務


private void startServicesIfNeeded(Class<?>[] services) {//如果已經啟動了就返回if (mServicesStarted) {return;}//如果沒啟動完成完成if (!mBootCompleted) {if ("1".equals(SystemProperties.get("sys.boot_completed"))) {mBootCompleted = true;if (DEBUG) Log.v(TAG, "BOOT_COMPLETED was already sent");}}final int N = services.length;for (int i=0; i<N; i++) {Class<?> cl = services[i];if (DEBUG) Log.d(TAG, "loading: " + cl);try {Object newService = SystemUIFactory.getInstance().createInstance(cl);mServices[i] = (SystemUI) ((newService == null) ? cl.newInstance() : newService);} catch (IllegalAccessException ex) {throw new RuntimeException(ex);} catch (InstantiationException ex) {throw new RuntimeException(ex);}//啟動服務 mServices[i].start();//如果啟動完成了if (mBootCompleted) {mServices[i].onBootCompleted();}}mServicesStarted = true;}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

這里以com.android.systemui.statusbar.SystemBars.class為例,講解一下


三、狀態欄和導航欄 的啟動

SystemBars的start方法會創建一個ServiceMonitor(服務監聽者),會進入到ServiceMonitor的start方法

public class SystemBars extends SystemUI implements ServiceMonitor.Callbacks {......public void start() {// ServiceMonitor是服務監聽者mServiceMonitor = new ServiceMonitor(TAG, DEBUG, mContext, Settings.Secure.BAR_SERVICE_COMPONENT, this);mServiceMonitor.start(); // will call onNoService if no remote service is found}...... }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在ServiceMonitor的start方法啟動

public class ServiceMonitor {...... public void start() {......mHandler.sendEmptyMessage(MSG_START_SERVICE);}...... }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在Handler里處理這個MSG_START_SERVICE

public class ServiceMonitor {...... private final Handler mHandler = new Handler() {public void handleMessage(Message msg) {switch(msg.what) {case MSG_START_SERVICE://啟動服務startService();break;case MSG_CONTINUE_START_SERVICE:continueStartService();break;case MSG_STOP_SERVICE:stopService();break;case MSG_PACKAGE_INTENT:packageIntent((Intent)msg.obj);break;case MSG_CHECK_BOUND:checkBound();break;case MSG_SERVICE_DISCONNECTED:serviceDisconnected((ComponentName)msg.obj);break;}}};......}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

startService方法如下


public class ServiceMonitor {...... private void startService() {//獲取服務組件名稱mServiceName = getComponentNameFromSetting();//如果為空,回調服務的onNoService方法if (mServiceName == null) {mBound = false;mCallbacks.onNoService();} else {//不為空,回調服務的的onServiceStartAttempt方法long delay = mCallbacks.onServiceStartAttempt();mHandler.sendEmptyMessageDelayed(MSG_CONTINUE_START_SERVICE, delay);}}......}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

這里對mServiceName是否為空進行判斷,總之無論如何它最終都會啟動這個服務。

回調SystemBars的onNoService里創建StatusBar

public class SystemBars extends SystemUI implements ServiceMonitor.Callbacks {......@Overridepublic void onNoService() {if (DEBUG) Log.d(TAG, "onNoService");//創建StatusBarcreateStatusBarFromConfig(); // fallback to using an in-process implementation}......
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
private void createStatusBarFromConfig() {//config_statusBarComponent就是PhoneStatusBarfinal String clsName = mContext.getString(R.string.config_statusBarComponent);Class<?> cls = null;try {cls = mContext.getClassLoader().loadClass(clsName);} catch (Throwable t) {throw andLog("Error loading status bar component: " + clsName, t);}try {//創建BaseStatusBar實例mStatusBar = (BaseStatusBar) cls.newInstance();} catch (Throwable t) {throw andLog("Error creating status bar component: " + clsName, t);}mStatusBar.mContext = mContext;mStatusBar.mComponents = mComponents;//啟動mStatusBar.start();}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

在createStatusBarFromConfig方法里會獲取一個config_statusBarComponent的字符串值,這個值就是PhoneStatusBar的clasName

所以這里的mStatusBar是PhoneStatusBar實例,啟動了PhoneStatusBar

PhoneStatusBar的start方法

public class PhoneStatusBar extends BaseStatusBar implements DemoMode, DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener,HeadsUpManager.OnHeadsUpChangedListener {......public void start() {......//調用父類的start方法,在父類BaseStatusBar里調用createAndAddWindows方法// 3.1super.start(); // calls createAndAddWindows()......//添加導航欄// 3.2addNavigationBar();......}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

它會回調父類BaseStatusBar 的start方法

3.1、 super.start()

public abstract class BaseStatusBar extends SystemUI implementsCommandQueue.Callbacks, ActivatableNotificationView.OnActivatedListener,ExpandableNotificationRow.ExpansionLogger, NotificationData.Environment,ExpandableNotificationRow.OnExpandClickListener,OnGutsClosedListener { ......public void start() {....../*實例化IStatusBarService,隨后BaseStatusBar將自己注冊到IStatusBarService之中。以此聲明本實例才是狀態欄的真正實現者,IStatusBarService會將其所接受到的請求轉發給本實例。IStatusBarService會保存SystemUi的狀態信息,避免SystemUi崩潰而造成信息的丟失*/mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));......//IStatusBarService與BaseStatusBar進行通信的橋梁。mCommandQueue = new CommandQueue(this);/*switches則存儲了一些雜項:禁用功能列表,SystemUIVisiblity,是否在導航欄中顯示虛擬的菜單鍵,輸入法窗口是否可見、輸入法窗口是否消費BACK鍵、是否接入了實體鍵盤、實體鍵盤是否被啟用。*/int[] switches = new int[9];ArrayList<IBinder> binders = new ArrayList<IBinder>();/*它保存了用于顯示在狀態欄的系統狀態區中的狀態圖標列表。在完成注冊之后,IStatusBarService將會在其中填充兩個數組,一個字符串數組用于表示狀態的名稱,一個StatusBarIcon類型的數組用于存儲需要顯示的圖標資源。*/ArrayList<String> iconSlots = new ArrayList<>();ArrayList<StatusBarIcon> icons = new ArrayList<>();Rect fullscreenStackBounds = new Rect();Rect dockedStackBounds = new Rect();//IStatusBarService注冊一些信息try {mBarService.registerStatusBar(mCommandQueue, iconSlots, icons, switches, binders,fullscreenStackBounds, dockedStackBounds);} catch (RemoteException ex) {}//創建狀態欄窗口createAndAddWindows();......}......}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

BaseStatusBar進行一些設置,獲取了IStatusBarService實例并注冊一些信息到IStatusBarService中,IStatusBarService是一個系統服務,BaseStatusBar將自己注冊到IStatusBarService之中,IStatusBarService會把操作狀態欄和導航欄的請求轉發給BaseStatusBar

為了保證SystemUI意外退出后不會發生信息丟失,IStatusBarService保存了所有需要狀態欄與導航欄進行顯示或處理的信息副本。 在注冊時將一個繼承自IStatusBar.Stub的CommandQueue的實例注冊到IStatusBarService以建立通信,并將信息副本取回。

public class CommandQueue extends IStatusBar.Stub {
  • 1

IStatusBarService的真身是StatusBarManagerService

路徑:./services/core/java/com/android/server/statusbar/StatusBarManagerService.java

它的注冊方法做一些數據的初始化

public class StatusBarManagerService extends IStatusBarService.Stub {......public void registerStatusBar(IStatusBar bar, List<String> iconSlots,List<StatusBarIcon> iconList, int switches[], List<IBinder> binders,Rect fullscreenStackBounds, Rect dockedStackBounds) {//檢查權限 enforceStatusBarService();mBar = bar;synchronized (mIcons) {for (String slot : mIcons.keySet()) {iconSlots.add(slot);iconList.add(mIcons.get(slot));}}synchronized (mLock) {switches[0] = gatherDisableActionsLocked(mCurrentUserId, 1);switches[1] = mSystemUiVisibility;switches[2] = mMenuVisible ? 1 : 0;switches[3] = mImeWindowVis;switches[4] = mImeBackDisposition;switches[5] = mShowImeSwitcher ? 1 : 0;switches[6] = gatherDisableActionsLocked(mCurrentUserId, 2);switches[7] = mFullscreenStackSysUiVisibility;switches[8] = mDockedStackSysUiVisibility;binders.add(mImeToken);fullscreenStackBounds.set(mFullscreenStackBounds);dockedStackBounds.set(mDockedStackBounds);}}......}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

這幾者的關系如下

?
回到PhoneStatusBar中, 父類BaseStatusBar中的createAndAddWindows為抽象方法,由子類實現,看下PhoneStatusBar的?
createAndAddWindows

@Overridepublic void createAndAddWindows() {//添加狀態欄窗口addStatusBarWindow();}
  • 1
  • 2
  • 3
  • 4
  • 5

方法實現如下

private void addStatusBarWindow() {//創建控件 makeStatusBarView();//創建StatusBarWindowManager實例 mStatusBarWindowManager = new StatusBarWindowManager(mContext);//創建遠程輸入控制實例 mRemoteInputController = new RemoteInputController(mStatusBarWindowManager,mHeadsUpManager);//添加狀態欄窗口 mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight());}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

看下makeStatusBarView方法

makeStatusBarView的方法里調用 inflateStatusBarWindow(context)加載布局

protected void inflateStatusBarWindow(Context context) {mStatusBarWindow = (StatusBarWindowView) View.inflate(context, R.layout.super_status_bar, null);}
  • 1
  • 2
  • 3

這里介紹下布局

狀態欄布局介紹

整個狀態欄的父布局是R.layout.super_status_bar,對應的是StatusBarWindowView這個自定義布局.

<com.android.systemui.statusbar.phone.StatusBarWindowView xmlns:android="http://schemas.android.com/apk/res/android"xmlns:sysui="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true">......<!--正常狀態欄下的布局 --><include layout="@layout/status_bar"android:layout_width="match_parent"android:layout_height="@dimen/status_bar_height" /><!--狀態欄圖標下的SeekBar布局 --><include layout="@layout/brightness_mirror" /><!--車載模式的布局 --><ViewStub android:id="@+id/fullscreen_user_switcher_stub"android:layout="@layout/car_fullscreen_user_switcher"android:layout_width="match_parent"android:layout_height="match_parent"/><!--狀態欄下拉的布局 --><include layout="@layout/status_bar_expanded"android:layout_width="match_parent"android:layout_height="match_parent"android:visibility="gone" /></com.android.systemui.statusbar.phone.StatusBarWindowView>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

我這里以主要的布局層次做介紹,結合圖片分析會更加清楚

StatusBarWindowView里有幾個主要的布局

  • layout/status_bar
  • layout/brightness_mirror
  • layout/status_bar_expanded

如下圖?


1.layout/status_bar

這個是正常狀態下(未下拉的狀態欄圖標區域)

這個布局對應的是PhoneStatusBarView

<com.android.systemui.statusbar.phone.PhoneStatusBarView xmlns:android="http://schemas.android.com/apk/res/android"xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"android:id="@+id/status_bar"android:background="@drawable/system_bar_background"android:orientation="vertical"android:focusable="false"android:descendantFocusability="afterDescendants">......<!--狀態欄 --><LinearLayout android:id="@+id/status_bar_contents"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingStart="6dp"android:paddingEnd="8dp"android:orientation="horizontal"><!-- The alpha of this area is controlled from both PhoneStatusBarTransitions andPhoneStatusBar (DISABLE_NOTIFICATION_ICONS). --><!-- 通知圖標區域--><com.android.systemui.statusbar.AlphaOptimizedFrameLayout android:id="@+id/notification_icon_area"android:layout_width="0dip"android:layout_height="match_parent"android:layout_weight="1"android:orientation="horizontal" /><!-- 系統圖標區域 --><com.android.keyguard.AlphaOptimizedLinearLayout android:id="@+id/system_icon_area"android:layout_width="wrap_content"android:layout_height="match_parent"android:orientation="horizontal"><!-- 系統圖標 --><include layout="@layout/system_icons" /><!-- 時鐘信息 --><com.android.systemui.statusbar.policy.Clock android:id="@+id/clock"android:textAppearance="@style/TextAppearance.StatusBar.Clock"android:layout_width="wrap_content"android:layout_height="match_parent"android:singleLine="true"android:paddingStart="@dimen/status_bar_clock_starting_padding"android:paddingEnd="@dimen/status_bar_clock_end_padding"android:gravity="center_vertical|start"/></com.android.keyguard.AlphaOptimizedLinearLayout></LinearLayout></com.android.systemui.statusbar.phone.PhoneStatusBarView>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54

以下是細節圖,連線表示層次結構


其中,狀態欄的區域分為以下幾種

  • 通知欄圖標,在狀態欄的最左側顯示通知信息,比如來了一個短信,那么就會彈出一個短信圖標
  • 時間信息,顯示一個時間,比如上午9:58
  • 信號圖標,顯示手機信號,wifi信號等
  • 電量圖標,顯示當前電量狀態
  • 狀態圖標,wifi,藍牙等開關狀態

2.@layout/brightness_mirror

這個布局就是中間那個調整亮度的seekBar.沒啥好介紹的.


3.@layout/status_bar_expanded

這個布局是下拉時的狀態欄的布局

<com.android.systemui.statusbar.phone.NotificationPanelView xmlns:android="http://schemas.android.com/apk/res/android"xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"android:id="@+id/notification_panel"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/transparent"><!--鎖屏時的時鐘布局 --><include layout="@layout/keyguard_status_view"android:layout_height="wrap_content"android:visibility="gone" /><com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer android:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="@integer/notification_panel_layout_gravity"android:id="@+id/notification_container_parent"android:clipToPadding="false"android:clipChildren="false"><!--quciksetting區域 --><com.android.systemui.AutoReinflateContainer android:id="@+id/qs_auto_reinflate_container"android:layout="@layout/qs_panel"android:layout_width="@dimen/notification_panel_width"android:layout_height="match_parent"android:layout_gravity="@integer/notification_panel_layout_gravity"android:clipToPadding="false"android:clipChildren="false" /><!-- 通知欄區域 --><com.android.systemui.statusbar.stack.NotificationStackScrollLayout android:id="@+id/notification_stack_scroller"android:layout_width="@dimen/notification_panel_width"android:layout_height="match_parent"android:layout_gravity="@integer/notification_panel_layout_gravity"android:layout_marginBottom="@dimen/close_handle_underlap" /><!--鎖屏切換 --><ViewStub android:id="@+id/keyguard_user_switcher"android:layout="@layout/keyguard_user_switcher"android:layout_height="match_parent"android:layout_width="match_parent" /><!--鎖屏下的狀態欄 --><include layout="@layout/keyguard_status_bar"android:visibility="invisible" /></com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer><!--鎖屏界面底部的圖標 --><include layout="@layout/keyguard_bottom_area"android:visibility="gone" /></com.android.systemui.statusbar.phone.NotificationPanelView><!-- end of sliding panel -->
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

細節圖



創建完布局后,就會添加窗口到WindowManager里,這樣狀態欄就創建完成了.接下來會回到3.2 addNavigationBar()的步驟中.

3.2、addNavigationBar

這個方法是添加底部的導航欄的,就是那些home鍵,back鍵所在的區域.

public class PhoneStatusBar extends BaseStatusBar implements DemoMode, DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener,HeadsUpManager.OnHeadsUpChangedListener {......protected void addNavigationBar() {if (mNavigationBarView == null) return;//初始化導航欄prepareNavigationBarView();//添加到WindowManager中mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());}......}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在這個方法里先初始化導航欄,然后把導航欄添加到窗口中.

prepareNavigationBarView()

public class PhoneStatusBar extends BaseStatusBar implements DemoMode, DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener,HeadsUpManager.OnHeadsUpChangedListener {......private void prepareNavigationBarView() {//重新初始化 mNavigationBarView.reorient();//最近應用鍵ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();recentsButton.setOnClickListener(mRecentsClickListener);recentsButton.setOnTouchListener(mRecentsPreloadOnTouchListener);recentsButton.setLongClickable(true);recentsButton.setOnLongClickListener(mRecentsLongClickListener);//后退鍵ButtonDispatcher backButton = mNavigationBarView.getBackButton();backButton.setLongClickable(true);backButton.setOnLongClickListener(mLongPressBackListener);//home鍵ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();homeButton.setOnTouchListener(mHomeActionListener);homeButton.setOnLongClickListener(mLongPressHomeListener);//監聽配置改變mAssistManager.onConfigurationChanged();}......}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

四、結束

關于SystemUI的狀態欄和導航欄就介紹完了,講的很淺顯,只是從整體上梳理了下流程.

原文地址: http://blog.csdn.net/qq_31530015/article/details/53507968

總結

以上是生活随笔為你收集整理的Android 7.0 SystemUI 之启动和状态栏和导航栏简介的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。