zoukankan      html  css  js  c++  java
  • android 界面 状态栏按下 menu键 显示不出,无响应

    1.问题描述:


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




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




    2)确认问题原因:


    menu键按下处理的关键:




    文件:
    PhoneWindow.java (frameworksasepolicysrccomandroidinternalpolicyimpl)


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


        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 (frameworksaseservicesjavacomandroidserverwm)


        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;//屏蔽掉
                }//这里就是问题的原因
    }
  • 相关阅读:
    聚集索引和非聚集索引的区别有哪些
    材料管理框架:一个共通的viewModel搞定所有的分页查询
    常用到的Linux命令
    Mybatis的使用中的一些不太注意的技巧
    Maven使用yuicompressor-maven-plugin打包压缩css、js文件
    Redis实现Mybatis的二级缓存
    zookeeper分布式协调服务的使用一
    Redis Cluster集群
    Spring+Struts2+Hibernate的整合
    SpringMVC,采用的是SpringJDBC
  • 原文地址:https://www.cnblogs.com/liulaolaiu/p/11744662.html
Copyright © 2011-2022 走看看