Onscreen Input Methods | Android Developers - Huihoo
文章推薦指數: 80 %
Starting from Android 1.5, the Android platform offers an Input Method Framework (IMF) that lets you create on-screen input methods such as software ...
Home
Startseite
ホーム
主页
首頁
SDK
DevGuide
Handbuch
Guía
Guide
Guida
開発ガイド
开发人员指南
開發指南
Reference
Referenz
Referencia
Référence
Riferimento
リファレンス
参考
參考資料
Resources
Videos
ビデオ
Blog
ブログ
博客
網誌
Android.com
TechnicalResources
SampleCode
Beispielcode
Códigodeejemplo
Exempledecode
Codicediesempio
サンプルコード
GettingtheSamples
Articles
Tutorials
Lernprogramme
Tutoriales
Didacticiels
Esercitazioni
チュートリアル
Topics
Community
Comunidad
Communauté
コミュニティ
社区
社群
DeveloperForums
IRC,Twitter
More
CommonTasks
TroubleshootingTips
FAQs
AppFrameworkFAQ
LicensingFAQ
SecurityFAQ
Articles>
OnscreenInputMethods
Seealso
CreatinganInput
Method
SoftKeyboardsample
StartingfromAndroid1.5,theAndroidplatformoffersanInputMethod
Framework(IMF)thatletsyoucreateon-screeninputmethodssuchassoftware
keyboards.ThisarticleprovideanoverviewofwhatAndroidinputmethodeditors
(IMEs)areandwhatanapplicationneedstodotoworkwellwiththem.TheIMF
isdesignedtosupportnewclassesofAndroiddevices,suchasthosewithout
hardwarekeyboards,soitisimportantthatyourapplicationworkswellwiththe
IMFandoffersagreatexperienceforusers.
Whatisaninputmethod?
TheAndroidIMFisdesignedtosupportavarietyofIMEs,includingsoft
keyboard,hand-writingrecognizers,andhardkeyboardtranslators.Ourfocus,
however,willbeonsoftkeyboards,sincethisisthekindofinputmethodthat
iscurrentlypartoftheplatform.
AuserwillusuallyaccessthecurrentIMEbytappingonatextviewto
edit,asshownhereinthehomescreen:
Thesoftkeyboardispositionedatthebottomofthescreenoverthe
application'swindow.Toorganizetheavailablespacebetweentheapplication
andIME,weuseafewapproaches;theoneshownhereiscalledpanand
scan,andsimplyinvolvesscrollingtheapplicationwindowaroundsothat
thecurrentlyfocusedviewisvisible.Thisisthedefaultmode,sinceitisthe
safestforexistingapplications.
Mostoftenthepreferredscreenlayoutisaresize,wherethe
application'swindowisresizedtobeentirelyvisible.Anexampleisshown
here,whencomposingane-mailmessage:
Thesizeoftheapplicationwindowischangedsothatnoneofitishiddenby
theIME,allowingfullaccesstoboththeapplicationandIME.Thisofcourse
onlyworksforapplicationsthathavearesizeableareathatcanbereducedto
makeenoughspace,buttheverticalspaceinthismodeisactuallynolessthan
whatisavailableinlandscapeorientation,soveryoftenanapplicationcan
alreadyaccommodateit.
Thefinalmajormodeisfullscreenorextract
mode.ThisisusedwhentheIMEistoolargetoreasonablysharespace
withtheunderlyingapplication.WiththestandardIMEs,youwillonly
encounterthissituationwhenthescreenisinalandscapeorientation,
althoughotherIMEsarefreetouseitwhenevertheydesire.Inthis
casetheapplicationwindowisleftas-is,andtheIMEsimplydisplays
fullscreenontopofit,asshownhere:
BecausetheIMEiscoveringtheapplication,ithasitsowneditingarea,
whichshowsthetextactuallycontainedintheapplication.Therearealsosome
limitedopportunitiestheapplicationhastocustomizepartsoftheIME(the
"done"buttonatthetopandenterkeylabelatthebottom)toimprovetheuser
experience.
BasicXMLattributesforcontrollingIMEs
Thereareanumberofthingsthesystemdoestotrytohelpexisting
applicationsworkwithIMEsaswellaspossible,suchas:
Usepanandscanmodebydefault,unlessitcanreasonablyguessthat
resizemodewillworkbytheexistenceoflists,scrollviews,etc.
AnalyzethevariousexistingTextViewattributestoguessatthekindof
content(numbers,plaintext,etc)tohelpthesoftkeyboarddisplayan
appropriatekeylayout.
AssignafewdefaultactionstothefullscreenIME,suchas"nextfield"
and"done".
Therearealsosomesimplethingsyoucandoinyourapplicationthatwill
oftengreatlyimproveitsuserexperience.Exceptwhereexplicitlymentioned,
thesewillworkinanyAndroidplatformversion,eventhoseprevioustoAndroid
1.5(sincetheywillsimplyignorethesenewoptions).
SpecifyingeachEditTextcontrol'sinputtype
Themostimportantthingforanapplicationtodoistousethenew
android:inputType
attributeoneachEditText.Theattributeprovidesmuchricher
information
aboutthetextcontent.Thisattributeactuallyreplacesmanyexisting
attributes(android:password,
android:singleLine,
android:numeric,
android:phoneNumber,
android:capitalize,
android:autoText,and
android:editable).Ifyouspecifytheolderattributes
andthenewandroid:inputTypeattribute,thesystemuses
android:inputTypeandignorestheothers.
Theandroid:inputTypeattributehasthreepieces:
Theclassistheoverallinterpretationofcharacters.The
currentlysupportedclassesaretext(plaintext),
number(decimalnumber),phone(phonenumber),and
datetime(adateortime).
Thevariationisafurtherrefinementontheclass.Inthe
attributeyouwillnormallyspecifytheclassandvarianttogether,withthe
classasaprefix.Forexample,textEmailAddressisatextfield
wheretheuserwillentersomethingthatisane-mailaddress([email protected])so
thekeylayoutwillhavean'@'characterineasyaccess,and
numberSignedisanumericfieldwithasign.Ifonlytheclassis
specified,thenyougetthedefault/genericvariant.
Additionalflagscanbespecifiedthatsupplyfurtherrefinement.
Theseflagsarespecifictoaclass.Forexample,someflagsforthe
textclassaretextCapSentences,
textAutoCorrect,andtextMultiline.
Asanexample,hereisthenewEditTextfortheIMapplication'smessagetextview:
延伸文章資訊
- 1Create an input method | Android Developers
- 2InputMethodManager | Android Developers
- 3How to create an Input Method android? - Stack Overflow
If you want want to make sure that your keyboard shows, you need to add other files as well. Like...
- 4src/com/android/inputmethod/pinyin/PinyinIME.java
* The current IME status. *. * @see com.android.inputmethod.pinyin.PinyinIME.ImeState.
- 5Onscreen Input Methods | Android Developers - Huihoo
Starting from Android 1.5, the Android platform offers an Input Method Framework (IMF) that lets ...