平板界面状态栏按下menu键显示不出,无响应

在4.1系统且分辨率为768*1024的平板上,launcher界面menu键按下无响应。问题源于`PhoneWindow.java`中的条件判断,针对xlage屏幕且目标SDK版本大于等于HONEYCOMB的应用不显示options面板。通过屏蔽特定代码段,修复menu键弹出选项的问题。
1.问题描述:


在4.1的系统下,调试机器是768*1024的
默认:  在launcher 界面时状态栏显示menu键,menu键可以显示,但是按下menu键时却没有相应界面弹出,
但是原来的机器:1024*600的就没有任何问题




1)查找原因:
launcher代码问题,通过不同的机器对比同样的代码,证明代码没有问题
资源布局问题:强行走1024*600的布局,证明布局没有问题
唯一区别代码尺寸不同,最后只能追查menu键按下的处理过程,最终确认原因。




2)确认问题原因:


menu键按下处理的关键:




文件:
PhoneWindow.java (frameworks\base\policy\src\com\android\internal\policy\impl)


按键按下后会走到一下的两个文件:


    public final boolean onKeyDownPanel(int featureId, KeyEvent event) {
}
    public final void onKeyUpPanel(int featureId, KeyEvent event) {
     ...
     openPanel(st, event);
     ...
}




    private void openPanel(PanelFeatureState st, KeyEvent event) {
        // System.out.println("Open panel: isOpen=" + st.isOpen);


        // Already open, return
        if (st.isOpen || isDestroyed()) {
            return;
        }


        // Don't open an options panel for honeycomb apps on xlarge devices.
        // (The app should be using an action bar for menu items.)
        if (st.featureId == FEATURE_OPTIONS_PANEL) {
            Context context = getContext();
            Configuration config = context.getResources().getConfiguration();
            boolean isXLarge = (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) ==
                    Configuration.SCREENLAYOUT_SIZE_XLARGE;
            boolean isHoneycombApp = context.getApplicationInfo().targetSdkVersion >=
                    android.os.Build.VERSION_CODES.HONEYCOMB;


            if (isXLarge && isHoneycombApp) {
                return;
            }//这里就是问题的原因
        }
           ...
}


3)//问题分析,条件有两个
isXLarge 和 isHoneycombApp
isXLarge 为真:
            boolean isXLarge = (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) ==
                    Configuration.SCREENLAYOUT_SIZE_XLARGE;




分析:文件:WindowManagerService.java (frameworks\base\services\java\com\android\server\wm)


    private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh) {
     ...
        // configuration.  DO NOT CHANGE!
        if (longSize < 470) {
            // This is shorter than an HVGA normal density screen (which
            // is 480 pixels on its long side).
            screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_SMALL;
            screenLayoutLong = false;
            screenLayoutCompatNeeded = false;
        } else {
            // What size is this screen screen?
            if (longSize >= 960 && shortSize >= 720) {
                // 1.5xVGA or larger screens at medium density are the point
                // at which we consider it to be an extra large screen.
                screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_XLARGE;//系统走的是这里,原因
            } else if (longSize >= 640 && shortSize >= 480) {
                // VGA or larger screens at medium density are the point
                // at which we consider it to be a large screen.
                screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_LARGE;
            } else {
                screenLayoutSize = Configuration.SCREENLAYOUT_SIZE_NORMAL;
            }
     ...
}


4)解决方法:在函数中屏蔽掉,问题解决,按menu键后弹出选项:
    private void openPanel(PanelFeatureState st, KeyEvent event) {
            if (isXLarge && isHoneycombApp) {
                ;//return;//屏蔽掉
            }//这里就是问题的原因
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值