android 键盘问题

来源:互联网 发布:淘宝怎么查看流量 编辑:程序博客网 时间:2024/04/29 03:46

 最近搞安卓4.0平板,系统起来后老是默认为硬键盘,怎么老是默认为硬键盘呢?怎么改为默认软键盘?一系列问题出现了。

  转载请注明出处:http://blog.csdn.net/harhy

 跟踪下Java语言:


                        在  android-4.0.4/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java中有这么一段

    @Override
    public void setHardKeyboardStatus(boolean available, boolean enabled) {
        if (DEBUG) {
            Slog.d(TAG, "Set hard keyboard status: available=" + available
                    + ", enabled=" + enabled);
        }
//available = true;
//enabled = false;

        mInputMethodSwitchButton.setHardKeyboardStatus(available);
        updateNotificationIcons();
        mInputMethodsPanel.setHardKeyboardStatus(available, enabled);
    }

我先假设两个值true。false。编译一下结果在右下角点击后显示是“OFF”也就是软件连接。打开浏览求点击输入时候仍然弹不出软键盘。推测一下估计在前面。往前跟踪



android-4.0.4/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/
StatusBar.java里面  

setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);

现在看switches[6] != 0推测这个为假,向上看switches是如何定义的的 有这个函数

try {
           
mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications,
                   
switches, binders);
        } catch (RemoteException ex) {
            // If the system process isn't there we're doomed anyway.
        }

android-4.0.4/frameworks/base/services/java/com/android/service/StatusBarMangerService.java 有这么一个注册

   // ================================================================================
    // Callbacks from the status bar service.
    // ================================================================================
    public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
            List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
            int switches[], List<IBinder> binders) {
        enforceStatusBarService();


        Slog.i(TAG, "registerStatusBar bar=" + bar);
        mBar = bar;
        synchronized (mIcons) {
            iconList.copyFrom(mIcons);
        }
        synchronized (mNotifications) {
            for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
                notificationKeys.add(e.getKey());
                notifications.add(e.getValue());
            }
        }
        synchronized (mLock) {
            switches[0] = gatherDisableActionsLocked();
            switches[1] = mSystemUiVisibility;
            switches[2] = mMenuVisible ? 1 : 0;
            switches[3] = mImeWindowVis;
            switches[4] = mImeBackDisposition;
            binders.add(mImeToken);
        }
        switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
   
    switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
    }

注意后面isHardKeyboardEnabled()查找这个函数

android-4.0.4/frameworks/base/services/java/com/android/service/wm/windowmangerservice.java里面有定义

    public boolean isHardKeyboardEnabled() {
        synchronized (mWindowMap) {
            return
mHardKeyboardEnabled;
        }

网上查找这个值mHardKeyboardEnabled

在上面可以发现

      // Determine whether a hard keyboard is available and enabled.
        boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;

        if (hardKeyboardAvailable != mHardKeyboardAvailable) {
            mHardKeyboardAvailable = hardKeyboardAvailable;



     
      mHardKeyboardEnabled =  false ;//本人添加


            mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
            mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
        }
        if (!mHardKeyboardEnabled) {
            config.keyboard = Configuration.KEYBOARD_NOKEYS;
        }

至于为什么要设置成false 要看最上面那一句话:        

boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; 这句话用来判断

如果想不添加那一句。就需要修改config.keyboard != Configuration.KEYBOARD_NOKEYS使这一个为 假 就ok了。

但是我找半天没找到。希望找到交流一下。谢谢!




原创粉丝点击