当前位置:操作系统 > 安卓/Android >>

Android4.0的StatusBar和NavigationBar

主要是注意平板和手机之间布局的区别:
几个关键的java类
SystemUIService
PhoneWindowManager
WindowManagerPolicy
PhoneStatusBar
TabletStatusBar
NavigationBar

 


    SystemUIService-->onCreate中判断加载平板布局还是手机布局
       [java]
<SPAN style="WHITE-SPACE: pre"> </SPAN>// Pick status bar or system bar.  
       IWindowManager wm = IWindowManager.Stub.asInte易做图ce( 
               ServiceManager.getService(Context.WINDOW_SERVICE)); 
       try { 
           SERVICES[0] = wm.canStatusBarHide() 
                   ? R.string.config_statusBarComponent 
                   : R.string.config_systemBarComponent; 
       } catch (RemoteException e) { 
           Slog.w(TAG, "Failing checking whether status bar can hide", e); 
       } 

  // Pick status bar or system bar.
        IWindowManager wm = IWindowManager.Stub.asInte易做图ce(
                ServiceManager.getService(Context.WINDOW_SERVICE));
        try {
            SERVICES[0] = wm.canStatusBarHide()
                    ? R.string.config_statusBarComponent
                    : R.string.config_systemBarComponent;
        } catch (RemoteException e) {
            Slog.w(TAG, "Failing checking whether status bar can hide", e);
        }    然后在frameworks\base\packages\systemui\res\values\config.xml中
        [html] view plaincopyprint?<SPAN style="WHITE-SPACE: pre"> </SPAN><string name="config_statusBarComponent" translatable="false">com.android.systemui.statusbar.phone.PhoneStatusBar</string> 
        <string name="config_systemBarComponent" translatable="false">com.android.systemui.statusbar.tablet.TabletStatusBar</string> 

 <string name="config_statusBarComponent" translatable="false">com.android.systemui.statusbar.phone.PhoneStatusBar</string>
        <string name="config_systemBarComponent" translatable="false">com.android.systemui.statusbar.tablet.TabletStatusBar</string>

    然后通过类加载器加载PhoneStatusBar或者TabletStatusBar。也就是手机的状态栏还是平板的状态栏。
    判断的关键就在wm.canStatusBarHide()这个方法里面。
    我们跳过几个类后最后跟进到PhoneWindowManager中:   
[java]
<SPAN style="WHITE-SPACE: pre"> </SPAN>public boolean canStatusBarHide() { 
            return mStatusBarCanHide; 
        } 

 public boolean canStatusBarHide() {
            return mStatusBarCanHide;
        }    mStatusBarCanHide是一个成员变量,修改它值得地方在:

     public void setInitialDisplaySize(int width, int height) {...}中。
[java]
<SPAN style="WHITE-SPACE: pre"> </SPAN>int shortSizeDp = shortSize 
                * DisplayMetrics.DENSITY_DEFAULT 
                / DisplayMetrics.DENSITY_DEVICE; 
        mStatusBarCanHide = shortSizeDp < 600; 
        mStatusBarHeight = mContext.getResources().getDimensionPixelSize( 
                mStatusBarCanHide 
                ? com.android.internal.R.dimen.status_bar_height 
                : com.android.internal.R.dimen.system_bar_height); 
 
        mHasNavigationBar = mContext.getResources().getBoolean( 
                com.android.internal.R.bool.config_showNavigationBar); 
        // Allow a system property to override this. Used by the emulator.  
        // See also hasNavigationBar().  
        String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); 
        if (! "".equals(navBarOverride)) { 
            if      (navBarOverride.equals("1")) mHasNavigationBar = false; 
            else if (navBarOverride.equals("0")) mHasNavigationBar = true; 
        } 

 int shortSizeDp = shortSize
                * DisplayMetrics.DENSITY_DEFAULT
                / DisplayMetrics.DENSITY_DEVICE;
        mStatusBarCanHide = shortSizeDp < 600;
        mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
                mStatusBarCanHide
                ? com.android.internal.R.dimen.status_bar_height
                : com.android.internal.R.dimen.system_bar_height);

        mHasNavigationBar = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_showNavigationBar);
        // Allow a system property to override this. Used by the emulator.
        // See also hasNavigationBar().
    &

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,