码迷,mamicode.com
首页 > 移动开发 > 详细

实现一个简易Android输入法(没有键盘)

时间:2015-06-11 21:01:04      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

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

实现一个简易Android输入法(没有键盘)

标签:

原文地址:http://www.cnblogs.com/Lovetuya/p/4570028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!