2017-02-22 61 views
0

example如何TextView中添加到自定義鍵盤頂部

@Override public View onCreateInputView() { 
    kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null); 
    keyboard = new Keyboard(this, R.xml.qwerty); kv.setKeyboard(keyboard); 
    UserDictionary.Words.addWord(this, "MadeUpWord", 10, "Mad", Locale.getDefault()); 
    kv.setOnKeyboardActionListener(this); 
    return kv; 
} 

回答

0

你可以按照下面的鏈接進行自定義鍵盤:

Create a Custom Keyboard on Android

創建一個文件名爲RES /佈局/鍵盤.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是每當按下鍵盤上的按鍵時顯示的短暫彈出窗口的佈局。它包含一個單獨的TextView。創建一個文件名爲RES /佈局/ 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> 
+0

感謝您的答覆,但我已經做到了這一點,現在我需要在鍵盤的上方,顯示文本建議添加的TextView ... –

相關問題