如何去写一个输入法(1)

最近有幸做了一次输入法的开发,在此处共享一下,今天先写一部分

输入法其实就是一个服务,基本上输入法都通过继承自谷歌提供InputMethodService类来实现输入法。然后要重写几个关键的回调函数就可以了。这几个函数包括:

(1) onCreateInputView()

    我们先来看看API说明:

Create and return the viewhierarchy used for the input area (such as a soft keyboard). This will be calledonce, when the input area is first displayed. You can return null to have noinput area; the default implementation returns null.

    大意就是说用于创建软键盘视图,输入法启动的时候之后只调用一次。默认为空。

 

     (2) onStartInput(EditorInfoeditorInfo, boolean restarting)

        我们先来看API说明:

          Called to inform the input method that text input has started inan editor. You should use this callback to initialize the state of your inputto match the state of the editor given to it.

        用于通知输入法,一个文本输入已经开始。在此处根据编辑框属性初始化你的输入法状态

     (3) onStartInputView(EditorInfoeditorInfo, boolean restarting)

        我们先来看API说明:

         Calledwhen the input view is being shown and input has started on a new editor. Thiswill always be called after onStartInput(EditorInfo, boolean),allowing you to do your general setup there and just view-specific setup here.You are guaranteed that onCreateInputView()will have been called some time before this function is called.

        当启动一个输入的时候会回调这个函数,主要用于自定义一些输入法视图。

     (4) onFinishInputView(booleanfinishingInput)

        Calledwhen the input view is being hidden from the user. This will be called eitherprior to hiding the window, or prior to switching to another target forediting.

       当输入法软键盘被隐藏的时候,(比如返回键)会调用。它会在应用的窗口消失或者切换编辑区域的之前调用,我们可以在此处做一些视图的隐藏工作。

     (5) onFinishInput()

        这个回调函数是在彻底结束当前输入状态的时候会调用,比如当前窗体隐藏或者切换编辑区域,但是如果是返回按键隐藏输入法则不会调用这个函数。

 


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值