Android Fragment:開發大螢幕平板時UserDictionaryAddWordFragment編輯後軟鍵盤

來源:互聯網
上載者:User

      昨天收到一個bug,描述如下:1 Enter Settings-->Language&input2 Choose personal dictionary3.Choose add in menu4.Input some word and choose personal dictionary[Expected result]The word can be added to dictionary and no any error[Error]The input panel can't hide進入添加使用者字典後編輯並退出,但是input panel不能自動隱藏。這個問題涉及到fragment的概念,關於理解fragment的概念,可以參考http://www.cnblogs.com/mybkn/articles/2455134.html。        添加使用者字典是在UserDictionaryAddWordFragment中進行的,UserDictionaryAddWordFragment繼承於Fragment。\packages\apps\Settings\src\com\android\settings\inputmethod\UserDictionaryAddWordFragment.java在它的onPause()方法中添加如下code:  boolean autoHide = getResources().getBoolean(R.bool.auto_hide_keyboard_when_onpause);        if (autoHide){www.2cto.com            ContexttContext = getActivity();           InputMethodManager imm =(InputMethodManager)getActivity().getSystemService(tContext.INPUT_METHOD_SERVICE);           imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),0);        }其中的R.bool.auto_hide_keyboard_when_onpause這個值在\packages\apps\Settings\res\value下的bool.xml中定義。smart-phone的這個值是false,value-sw600dp目錄下的bool.xml中的值為true。Fragment的onPause方法是在看不見這個Fragment的時候被調用的,所以把這段code加在onPause方法中即可實現退出這個Fragment時自動隱藏IME介面。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.