Android 11.0 修复在Settings首页,按键盘方向键不会全部选中而是选中单个选项

思路:
当获取到上下键值时,判断当前界面如果是设置主界面,就让它不执行全选代码

路径:frameworks/base/core/java/android/view/ViewRootImpl.java

if (direction!=33 || (direction == 33 && (!"com.android.settings.homepage.SettingsHomepageActivity".equals(cn.getClassName()))))
 private boolean performFocusNavigation(KeyEvent event) {
    
    
            if (direction != 0) {
    
    
                View focused = mView.findFocus();
                if (focused != null) {
    
    
                    View v = focused.focusSearch(direction);
                    if (v != null && v != focused) {
    
    
                        // do the math the get the interesting rect
                        // of previous focused into the coord system of
                        // newly focused view
                        focused.getFocusedRect(mTempRect);
                        if (mView instanceof ViewGroup) {
    
    
                            ((ViewGroup) mView).offsetDescendantRectToMyCoords(
                                    focused, mTempRect);
                            ((ViewGroup) mView).offsetRectIntoDescendantCoords(
                                    v, mTempRect);
                        }
+                        //wangrui On the home page of the settings, cancel the selection and select the first level directory instead
+                         am = (android.app.ActivityManager) mContext.getSystemService(ACTIVITY_SERVICE);
+                         cn = am.getRunningTasks(1).get(0).topActivity;
+                        if (direction!=33 || (direction == 33 && (!"com.android.settings.homepage.SettingsHomepageActivity".equals(cn.getClassName())))) {
    
    
+                            if (v.requestFocus(direction, mTempRect)) {
    
    
+                                playSoundEffect(SoundEffectConstants
+                                        .getContantForFocusDirection(direction));
+                                return true;
+                            }
+                        }

                    }
        }

猜你喜欢

转载自blog.csdn.net/qq_27494201/article/details/125147888