2014-09-18 18 views
11

Sto usando keyboardview per avere la mia tastiera.Crea popup del tasto premuto su una tastiera personalizzata

funziona bene, ma non posso fare l'effetto di ampliare il tasto premuto, così come la tastiera Android

zoom image

Queste sono le parti che utilizzano

<android.inputmethodservice.KeyboardView 
     android:id="@+id/keyboardview" 
     style="@style/Widget.KeyboardView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:shadowRadius="0" 
     android:visibility="visible" /> 

.

<style name="Widget.KeyboardView" parent="android:Widget.KeyboardView"> 
      <item name="android:background">@drawable/naranja</item> 
      <item name="android:keyBackground">@drawable/naranja</item> 
      <item name="android:keyTextSize">40sp</item> 
      <item name="android:keyTextColor">#d35400</item> 
      <item name="android:keyPreviewLayout">@layout/keyboard_popup_keyboard</item> 
      <item name="android:keyPreviewOffset">12dp</item> 
      <item name="android:keyPreviewHeight">80dp</item> 
      <item name="android:popupLayout">@layout/keyboard_popup_keyboard</item> 
     </style> 

.

XML/pop-up:

<?xml version="1.0" encoding="utf-8"?> 
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
    android:keyWidth="10%p" 
    android:keyHeight="10%p"> 
</Keyboard> 

Righe

 <Key 
       android:codes="81" 
       android:keyEdgeFlags="left" 
       android:keyLabel="Q" 
       android:popupCharacters="Q" 
       android:popupKeyboard="@xml/popup" /> 

    etc... 

Ho provato con il metodo OnKey, anche dal XML. Ma senza successo.

risposta

11

Per visualizzare solo le anteprime ingrandite, lo standard KeyboardView dovrebbe essere eseguito per impostazione predefinita. Non si desidera impostare un valore popupKeyboard poiché si tratta di una mini tastiera speciale che viene visualizzata con una pressione prolungata.

Presumo che stavate seguendo this tutorial. Prendete nota di queste righe nella sezione 3.3:

// Do not show the preview balloons 
mKeyboardView.setPreviewEnabled(false); 

invece impostare questo per true.

soluzione completa

Nel layout del l'attività:

<android.inputmethodservice.KeyboardView 
    android:id="@+id/keyboardview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:keyPreviewOffset="12dp" 
    android:keyPreviewLayout="@layout/kbpreview" 
    android:visibility="visible" /> 

Le proprietà importanti sono keyPreviewLayout, keyPreviewOffset e keyPreviewHeight.

layout/kbpreview.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:gb="http://schemas.android.com/apk/res-auto" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:background="@color/red" 
    android:textSize="30dp" /> 

xml/kb.xml

<?xml version="1.0" encoding="utf-8"?> 
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
    android:keyWidth="12.50%p" 
    android:keyHeight="10%p" > 

    <Row> 
     <Key android:codes="55" android:keyLabel="7" android:keyEdgeFlags="left" /> 
     <Key android:codes="56" android:keyLabel="8" /> 
     <Key android:codes="57" android:keyLabel="9" /> 
     <Key android:codes="65" android:keyLabel="A" android:horizontalGap="6.25%p" /> 
     <Key android:codes="66" android:keyLabel="B" /> 
     <Key android:codes="55006" android:keyLabel="CLR" android:keyEdgeFlags="right"/> 
    </Row> 

    <!-- and whatever else... --> 

</Keyboard> 

Nel codice attività

Keyboard mKeyboard = new Keyboard(this, R.xml.kb); 

    // Lookup the KeyboardView 
    KeyboardView mKeyboardView = (KeyboardView) findViewById(R.id.keyboardview); 

    // Attach the keyboard to the view 
    mKeyboardView.setKeyboard(mKeyboard); 

    // Key listener required 
    mKeyboardView.setOnKeyboardActionListener(myListener); 

Risultato

con il tasto '5' pressata:

enter image description here

Si può anche essere utile per verificare la KeyboardView source code.

+0

Voglio mostrare la keypreview sull'evento Long Press di keyboardview è possibile –

Problemi correlati