在android中的屏幕中间(或所需位置)显示键盘

时间:2013-12-13 07:07:51

标签: android android-softkeyboard

我为我的应用程序制作了一个自定义键盘,它只有一排键。 我想在屏幕中央而不是在底部显示键盘。 有没有办法做到这一点?

我正在使用这个xml代码:

enter code here

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:keyWidth="12.50%p"
    android:keyHeight="50%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:popupKeyboard="@xml/popup" 
        android:popupCharacters="aA" 
        android:horizontalGap="6.25%p" />
    <Key
         android:codes="66"    
         android:keyLabel="B" 
         android:popupKeyboard="@xml/popup" 
         android:popupCharacters="bB" />

</Row>

</Keyboard>

1 个答案:

答案 0 :(得分:1)

您可以在keyboard.xml文件下面创建

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

- &GT;

<Row>
    <Key
        android:codes="8"
        android:iconPreview="@drawable/k1hover"
        android:keyEdgeFlags="left"
        android:keyIcon="@drawable/key1" />
    <Key
        android:codes="9"
        android:iconPreview="@drawable/k2hover"
        android:keyIcon="@drawable/k2"
        />
    <Key
        android:codes="10"
        android:iconPreview="@drawable/k3hover"
        android:keyEdgeFlags="right"
         android:keyIcon="@drawable/k3"
        />


</Row>
<Row>
    <Key
        android:codes="11"
        android:iconPreview="@drawable/k4hover"
        android:keyEdgeFlags="left"
        android:keyIcon="@drawable/k4"
         />
    <Key
        android:codes="12"
        android:iconPreview="@drawable/k5hover"
        android:keyIcon="@drawable/k5"
       />
    <Key
        android:codes="13"
        android:iconPreview="@drawable/k6hover"
        android:keyEdgeFlags="right"
        android:keyIcon="@drawable/k6"
        />

    <Key
        android:codes="0"
        android:iconPreview="@drawable/nexthover"
        android:keyEdgeFlags="right"
        android:keyIcon="@drawable/keyboardnext" />
</Row>
<Row>
    <Key
        android:codes="14"
        android:iconPreview="@drawable/k7hover"
        android:keyEdgeFlags="left"
        android:keyIcon="@drawable/k7"
        />
    <Key
        android:codes="15"
        android:iconPreview="@drawable/k8hover"
        android:keyIcon="@drawable/k8"
        />
    <Key
        android:codes="16"
        android:iconPreview="@drawable/k9hover"
        android:keyEdgeFlags="right"
        android:keyIcon="@drawable/k9"
         />
</Row>
<Row>
     <Key
        android:codes="158"
        android:keyIcon="@drawable/dot"
         android:keyEdgeFlags="left"
        android:iconPreview="@drawable/dothover"
         />

      <Key
        android:codes="7"
        android:keyIcon="@drawable/k0"
        android:iconPreview="@drawable/k0hover"
         />
    <Key
        android:codes="67"
        android:iconPreview="@drawable/backhover"
        android:keyIcon="@drawable/keyboard_back"
        />

     <Key
        android:codes="35"
         android:keyEdgeFlags="right"
        android:keyIcon="@drawable/keydown"
        android:iconPreview="@drawable/keydownhover"
         />

</Row>

在特定位置调用此键盘:

    <com.kcs.pd.remote.utils.CustomKeyboardView
        android:id="@+id/keyboard_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_centerHorizontal="true"
        android:layout_marginRight="10px"
        android:layout_marginTop="10px"
        android:background="@drawable/keyboardback" >
    </com.kcs.pd.remote.utils.CustomKeyboardView>
</RelativeLayout>

在java文件中使用此代码为:

mKeyboard = new Keyboard(actLiverFunctionTests, R.xml.keyboard);
        mKeyboardView = (CustomKeyboardView) vwParent
                .findViewById(R.id.keyboard_view);

        mKeyboardView.setKeyboard(mKeyboard);
        mKeyboardView
                .setOnKeyboardActionListener(new BasicOnKeyboardActionListener(
                        actLiverFunctionTests));