2022年Android之输入法开发简单说明 .pdf

上传人:C****o 文档编号:40154829 上传时间:2022-09-08 格式:PDF 页数:6 大小:307.05KB
返回 下载 相关 举报
2022年Android之输入法开发简单说明 .pdf_第1页
第1页 / 共6页
2022年Android之输入法开发简单说明 .pdf_第2页
第2页 / 共6页
点击查看更多>>
资源描述

《2022年Android之输入法开发简单说明 .pdf》由会员分享,可在线阅读,更多相关《2022年Android之输入法开发简单说明 .pdf(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Android之输入法开发简单说明2010-08-19 14:46:08 作者:jezz 资深编辑有 1335 人浏览 网友评论0 条创建一个输入法,必须继承android.inputmethodservice.InputMethodService,它作为一个服务,监听所有EditText 的事件。看一个 AndroidManifest.xml文件的示例:view sourceprint?01.03.04.05.06.07.10.11.12.13.14.15.16.17.18.19.20.21.22.23.整个输入法的生命周期如下图所示:名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页

2、,共 6 页 -Input View软键盘的主界面,在InputMethodService.onCreateInputView()初始化.名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 6 页 -Candidates ViewThis is where potential word corrections or completions are presented to the user for selection.Again,this may or may not be relevant to your input method and youcan return null fr

3、om calls to InputMethodService.onCreateCandidatesView(),whichis the default behavior.InputMethodService.onStartInputView()输入法开始函数。(EditorInfo.inputType&EditorInfo.TYPE_CLASS_MASK)can be one of many differentvalues,including:TYPE_CLASS_NUMBER TYPE_CLASS_DATETIME TYPE_CLASS_PHONE TYPE_CLASS_TEXT See a

4、ndroid.text.InputType for more details.EditorInfo.inputType can contain other masked bits that indicate the class variation and other flags.For example,TYPE_TEXT_VARIATION_PASSWORD or TYPE_TEXT_VARIATION_URI or TYPE_TEXT_FLAG_AUTO_COMPLETE.Password fieldsPay specific attention when sending text to p

5、assword fields.Make sure that the password is not visible within your UI-in neither the input view nor the candidates view.And do not save the password anywhere without explicitly informing the user.名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 6 页 -Landscape vs.portraitThe UI needs to be able to scale between lan

6、dscape and portrait orientations.In non-fullscreen IME mode,leave sufficient space for the application to show the text field and any associated context.Preferably,no more than half the screen should be occupied by the IME.In fullscreen IME mode this is not an issue.Sending text to the application T

7、here are two ways to send text to the application.You can either send individual key events or you can edit the text around the cursor in the applications text field.To send a key event,you can simply construct KeyEvent objects and call InputConnection.sendKeyEvent().Here are some examples:view sour

8、ceprint?1.InputConnectionic=getCurrentInputConnection();2.longeventTime=SystemClock.uptimeMillis();3.ic.sendKeyEvent(newKeyEvent(eventTime,eventTime,4.KeyEvent.ACTION_DOWN,keyEventCode,0,0,0,0,5.KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE);6.ic.sendKeyEvent(newKeyEvent(SystemClock.upti

9、meMillis(),eventTime,7.KeyEvent.ACTION_UP,keyEventCode,0,0,0,0,8.KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE);Or use the convenience method:view sourceprint?1.InputMethodService.sendDownUpKeyEvents(keyEventCode);Note:It is recommended to use the above method for certain fields such as

10、phone number fields because of filters that may be applied to the text after each key press.Return key and delete key should also be sent as raw key events for certaininput types,as applications may be watching for specific key events in order to perform an action.When editing text in a text field,s

11、ome of the more useful methods on android.view.inputmethod.InputConnection are:getTextBeforeCursor()getTextAfterCursor()deleteSurroundingText()名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 6 页 -commitText()For example,lets say the text Fell is to the left of the cursor.And you want to replace it with Hello!:view s

12、ourceprint?1.InputConnectionic=getCurrentInputConnection();2.ic.deleteSurroundingText(4,0);mitText(Hello,1);mitText(!,1);Composing text before committingIf your input method does some kind of text prediction or requires multiple steps tocompose a word or glyph,you can show the progress in the text f

13、ield until the user commits the word and then you can replace the partial composition with the completed text.The text that is being composed will be highlighted in the text field insome fashion,such as an underline.view sourceprint?1.InputConnectionic=getCurrentInputConnection();2.ic.setComposingTe

14、xt(Composi,1);3.4.ic.setComposingText(Composin,1);mitText(Composing,1);Intercepting hard key events Even though the input method window doesnt have explicit focus,it receives hard key events first and can choose to consume them or forward them along to the application.For instance,you may want to co

15、nsume the directional keys to navigate within your UI for candidate selection during composition.Or you may want to trapthe back key to dismiss any popups originating from the input method window.Tointercept hard keys,override InputMethodService.onKeyDown()and InputMethodService.onKeyUp().Remember t

16、o call super.onKey*if you dont want to consume a certain key yourself.名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 6 页 -Other considerations Provide a way for the user to easily bring up any associated settings directly from the input method UI Provide a way for the user to switch to a different input method(mult

17、iple input methods may be installed)directly from the input method UI.Bring up the UI quickly-preload or lazy-load any large resources so that the usersees the input method quickly on tapping on a text field.And cache any resources and views for subsequent invocations of the input method.On the flip

18、 side,any large memory allocations should be released soon after the input method window is hidden so that applications can have sufficient memory to run.Consider using a delayed message to release resources if the input method is in a hidden state for a few seconds.Make sure that most common charac

19、ters can be entered using the input method,as users may use punctuation in passwords or user names and they shouldnt be stuck in a situation where they cant enter a certain character in order to gain access into a password-locked device.Samples For a real world example,with support for multiple input types and text prediction,see LatinIME source code.The Android 1.5 SDK also includes a SoftKeyboard sample as well 名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 6 页 -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁