2014-11-21 67 views
1

我想創建一個通用鍵盤,如Emoji。我正在關注this tutorial如何創建一個輸入法android?

我希望主軟鍵盤按原樣工作,或者我的意思是擴展它。只想在符號顯示時單擊更改mModeChangeKey上的佈局和事件。

當模式改變時,我想用表情符號顯示我的鍵盤。並將其添加爲其他表情符號。

的Manifest.xml

<service android:name="com.example.keyboardtesting.MyInputMethod" 
     android:label="@string/app_name" 
     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> 

還添加權限..

第一個按鈕點擊

startActivityForResult(new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS), 0); 

第二個按鈕點擊

InputMethodManager inputmethodmanager = (InputMethodManager) getSystemService("input_method"); 

    if (inputmethodmanager != null) 
    { 
     inputmethodmanager.showInputMethodPicker(); 
    } 

因爲這是由用戶選擇兩者。我們不能以編程方式進行。我也通過拉丁文和softkeyboard。但我仍然感到困惑。

MyInputMethod

public class MyInputMethod extends InputMethodService 
{ 
    private Keyboard mKeyboard; 

    private KeyboardView mInputView; 

    @Override 
    public void onInitializeInterface() 
    { 
     mKeyboard = new Keyboard(this, R.xml.qwerty); 
    } 

    @Override 
    public View onCreateInputView() 
    { 
     mInputView = (KeyboardView) getLayoutInflater().inflate(
       R.layout.input_black, null); 

     mInputView.setKeyboard(mKeyboard); 

     return mInputView; 
    } 
} 

簡單的詞:

我只是想表明我的鍵盤的Android設備上。我將在稍後添加事件。

+0

你是什麼意思的「改變模式」。當你點擊你創建的兩個按鈕時你期望得到什麼? – 2015-11-22 10:29:42

回答

0

如果您想要確保您的鍵盤顯示,您還需要添加其他文件。喜歡這個。

創建method.xml文件

<?xml version="1.0" encoding="utf-8"?> 
<input-method xmlns:android="http://schemas.android.com/apk/res/android"> 
<subtype 
    android:label="@string/subtype_en_US" 
    android:imeSubtypeLocale="en_US" 
    android:imeSubtypeMode="keyboard" /> 
</input-method> 

讓你的鍵盤佈局。佈局/ keyboard.xml

<?xml version="1.0" encoding="UTF-8"?> 
<android.inputmethodservice.KeyboardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/keyboard" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:keyPreviewLayout ="@layout/preview" 
/> 

的keyPreviewLayout是短命的彈出每當按下鍵盤上的鍵時顯示出來的佈局。

佈局/ preview.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:background="#ffff00" 
    android:textStyle="bold" 
    android:textSize="30sp" 
    >  
</TextView> 

接下來你需要做的qwerty.xml功能。你已經創建了服務類。但是你還沒有實施OnKeyboardActionListener。確保你做到了。