Android入力方式の開発
参照ドキュメント:http://developer.android.com/guide/topics/text/creating-input-method.html
インプットメソッドを実装するには、次の手順に従います.
入力プログラムの核心はサービスクラスであり、このクラスはInputMethodServiceから継承されなければならない.
まず、基本的な入力プログラムを実現する手順を見てみましょう.
(1)androidから継承する.inputmethodservice.InputMethodServiceのクラスで、入力方式のサービスクラスと呼ばれています.
(2)AndroidManifest.xmlファイルでこのサービスクラスを構成します.
(3)ソフトキーボードを表示するためのレイアウトファイルを作成する.
(4)InputMethodServiceクラスを上書きするonCreateInputViewメソッド.
(5)onCreateInputViewメソッドは,ステップ3で作成したレイアウトファイルに対応するViewオブジェクトを返す必要がある.戻る前に、ソフトキーボードボタンでイベントをクリックするなど、対応するコントロールのイベントを設定する必要があります.
(6)入力方式サービスクラスまたは他のクラスに、ボタンクリックイベント、物理キーボードイベントなど、ソフトキーボードにおけるキーイベントに応答するコードを記述する.
簡単な入力プログラムを実現します.
第一歩:Androidプロジェクトをsimpleと命名するinputmethodディレクトリ構造は次の図のとおりです.
ステップ2:InputMethodServiceから引き継いだAndroid InputMethodServiceクラスを作成し、Android.Manifest.xmlファイルでの構成:
AndroidInputMethodServiceクラス:
AndroidManifest.xml:ラベルに1つ追加
ラベルには、入力メソッドを構成するためのラベルも追加されています.つまり、「言語とキーボード」設定インタフェースでは、android:resourceプロパティが作成されている入力メソッドが表示されます.
入力方式リソースID.このリソースファイル(method.xml)はresxmlディレクトリにあります.コードは次のとおりです.
ラベルのandroid:settingActivityプロパティは、入力メソッド設定ウィンドウを作成できます.
InputMethodSetting.java:
setting.xml:
ステップ3:レイアウトファイルを作成します.このレイアウトファイルは実際にはソフトキーボードのレイアウトです.このレイアウトには、最初の4つの文字列(
インプットメソッドを実装するには、次の手順に従います.
入力プログラムの核心はサービスクラスであり、このクラスはInputMethodServiceから継承されなければならない.
まず、基本的な入力プログラムを実現する手順を見てみましょう.
(1)androidから継承する.inputmethodservice.InputMethodServiceのクラスで、入力方式のサービスクラスと呼ばれています.
(2)AndroidManifest.xmlファイルでこのサービスクラスを構成します.
(3)ソフトキーボードを表示するためのレイアウトファイルを作成する.
(4)InputMethodServiceクラスを上書きするonCreateInputViewメソッド.
(5)onCreateInputViewメソッドは,ステップ3で作成したレイアウトファイルに対応するViewオブジェクトを返す必要がある.戻る前に、ソフトキーボードボタンでイベントをクリックするなど、対応するコントロールのイベントを設定する必要があります.
(6)入力方式サービスクラスまたは他のクラスに、ボタンクリックイベント、物理キーボードイベントなど、ソフトキーボードにおけるキーイベントに応答するコードを記述する.
簡単な入力プログラムを実現します.
第一歩:Androidプロジェクトをsimpleと命名するinputmethodディレクトリ構造は次の図のとおりです.
ステップ2:InputMethodServiceから引き継いだAndroid InputMethodServiceクラスを作成し、Android.Manifest.xmlファイルでの構成:
AndroidInputMethodServiceクラス:
package net.csdn.leigo.inputmethod;
import net.csdn.leigo.inputmethod.R;
import android.inputmethodservice.InputMethodService;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.Button;
public class AndroidInputMethodService extends InputMethodService implements
OnClickListener {
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.csdn.leigo.inputmethod"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- Optional: an activity for controlling the IME settings -->
<activity android:name="net.csdn.leigo.inputmethod..InputMethodSetting" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<!-- Declares the input method service -->
<service
android:name="net.csdn.leigo.inputmethod.AndroidInputMethodService"
android:permission="android.permission.BIND_INPUT_METHOD" >
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data
android:name="android.view.im"
android:resource="@xml/method" />
</service>
</application>
</manifest>
入力方式サービスの構成時に設定する必要がありますandroid.permission.BIND_INPUT_METHOD"
権限、"android.view.InputMethod"
動作.入力方式リソースID.このリソースファイル(method.xml)はresxmlディレクトリにあります.コードは次のとおりです.
<?xml version="1.0" encoding="UTF-8"?>
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="net.csdn.leigo.inputmethod.InputMethodSetting"/>
InputMethodSetting.java:
package net.csdn.leigo.inputmethod;
import android.app.Activity;
import android.os.Bundle;
public class InputMethodSetting extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setting);
}
}
setting.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
</LinearLayout>
ステップ3:レイアウトファイルを作成します.このレイアウトファイルは実際にはソフトキーボードのレイアウトです.このレイアウトには、最初の4つの文字列(