实现一个简易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

posted @ 2015-06-11 20:08  行者,无疆  阅读(1388)  评论(0编辑  收藏  举报