zoukankan      html  css  js  c++  java
  • 实现一个简易Android输入法(没有键盘)

    1、现在AndroidManifest.xml 加入服务的声明: 

    权限要写清楚   android:permission="android.permission.BIND_INPUT_METHOD"

    1 <service 
    2             android:name=".server.imeservice"
    3             android:permission="android.permission.BIND_INPUT_METHOD">
    4             <intent-filter >
    5                 <action android:name="android.view.InputMethod"/>
    6             </intent-filter>
    7         </service>

    然后在res xml文件夹建立一个文件 method.xml:

    1 <input-method 
    2     xmlns:android="http://schemas.android.com/apk/res/android" />

    2、实现该服务:

    要继承 extends InputMethodService

     1 public class ImeService extends InputMethodService {
     2     
     3 public void onInitializeInterface() { // InputMethodService在启动时,系统会调用该方法,具体内容下回再表
     4   // 初始化 词典数据
     5   Log.d(TAG, "onInitializeInterface");
     6  }
     7 
     8  public void pickSuggestionManually(){
     9       Log.d(TAG, "input to text");
    10          getCurrentInputConnection().commitText(strSuggestion, 0); // 往输入框输出内容
    11          //setCandidatesViewShown(false); // 隐藏 CandidatesView
    12      }
    13 }

     相关接口参考: http://api.apkbus.com/reference/android/view/inputmethod/InputConnection.html

  • 相关阅读:
    事件对象阻止默认行为
    事件对象的属性和方法
    [MySQL] 中 Schema和Database的区别
    MyBatis-session-SqlSession
    Setting the Java Class Path
    MySQL Connector/J
    Backup and Recovery Types
    The MySQL Server
    Server SQL Modes
    MySQL Server and Server-Startup Programs
  • 原文地址:https://www.cnblogs.com/Lovetuya/p/4570028.html
Copyright © 2011-2022 走看看