在中间显示键盘(或期望的位置)在Android的屏幕 [英] Displaying keyboard at the middle(or at desired location) of the screen in android

查看:172
本文介绍了在中间显示键盘(或期望的位置)在Android的屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个做了一个自定义的键盘为我的应用程序有钥匙的一个单行。
欲在屏幕的中心,而不是在底部显示的键盘。
有没有办法做到这一点?

我使用这个XML code:

 在此输入code< XML版本=1.0编码=UTF-8&GT?;
<键盘的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:keyWidth =12.50%P
    机器人:keyHeight =50%P>
<行>
    <关键
        机器人:codeS =55
        机器人:keyLabel =7
        机器人:keyEdgeFlags =左/>
    <关键
        机器人:codeS =56
        机器人:keyLabel =8/>
    <关键
        机器人:codeS =57
        机器人:keyLabel =9/>
    <关键
        机器人:codeS =65
        机器人:keyLabel =A
        机器人:popupKeyboard =@ XML /弹出
        机器人:popupCharacters =AA
        机器人:horizo​​ntalGap的=6.25%P/>
    <关键
         机器人:codeS =66
         机器人:keyLabel =B
         机器人:popupKeyboard =@ XML /弹出
         机器人:popupCharacters =BB/>< /行>< /键盘>


解决方案

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

 的Apache授权版本2.0(以下简称许可证);
 你可能不使用这个文件除了在遵守许可。
 您可以在获得许可证的副本      http://www.apache.org/licenses/LICENSE-2.0 除非适用法律要求或书面同意,软件
 该许可证下发布分布在原样的基础,
 无担保或任何形式的条件,无论是前preSS或暗示的保证。
 查看许可证的特定语言的管理权限和
 根据许可证的限制。

- >

 <行>
    <关键
        机器人:codeS =8
        安卓图标preVIEW =@绘制/ k1hover
        机器人:keyEdgeFlags =左
        机器人:keyIcon =@绘制/ KEY1/>
    <关键
        机器人:codeS =9
        安卓图标preVIEW =@绘制/ k2hover
        机器人:keyIcon =@绘制/ K2
        />
    <关键
        机器人:codeS =10
        安卓图标preVIEW =@绘制/ k3hover
        机器人:keyEdgeFlags =右
         机器人:keyIcon =@绘制/ K3
        />
< /行>
<行>
    <关键
        机器人:codeS =11
        安卓图标preVIEW =@绘制/ k4hover
        机器人:keyEdgeFlags =左
        机器人:keyIcon =@绘制/ K4
         />
    <关键
        机器人:codeS =12
        安卓图标preVIEW =@绘制/ k5hover
        机器人:keyIcon =@绘制/ K5
       />
    <关键
        机器人:codeS =13
        安卓图标preVIEW =@绘制/ k6hover
        机器人:keyEdgeFlags =右
        机器人:keyIcon =@绘制/ K6
        />    <关键
        机器人:codeS =0
        安卓图标preVIEW =@绘制/ nexthover
        机器人:keyEdgeFlags =右
        机器人:keyIcon =@绘制/ keyboardnext/>
< /行>
<行>
    <关键
        机器人:codeS =14
        安卓图标preVIEW =@绘制/ k7hover
        机器人:keyEdgeFlags =左
        机器人:keyIcon =@绘制/ K7
        />
    <关键
        机器人:codeS =15
        安卓图标preVIEW =@绘制/ k8hover
        机器人:keyIcon =@绘制/ K8
        />
    <关键
        机器人:codeS =16
        安卓图标preVIEW =@绘制/ k9hover
        机器人:keyEdgeFlags =右
        机器人:keyIcon =@绘制/ K9
         />
< /行>
<行>
     <关键
        机器人:codeS =158
        机器人:keyIcon =@绘制/点
         机器人:keyEdgeFlags =左
        安卓图标preVIEW =@绘制/ dothover
         />      <关键
        机器人:codeS =7
        机器人:keyIcon =@绘制/ K0
        安卓图标preVIEW =@绘制/ k0hover
         />
    <关键
        机器人:codeS =67
        安卓图标preVIEW =@绘制/ backhover
        机器人:keyIcon =@绘制/ keyboard_back
        />     <关键
        机器人:codeS =35
         机器人:keyEdgeFlags =右
        机器人:keyIcon =@绘制/ KEYDOWN
        安卓图标preVIEW =@绘制/ keydownhover
         />< /行>

在特定位置调用该键盘:

 < com.kcs.pd.remote.utils.CustomKeyboardView
        机器人:ID =@ + ID / keyboard_view
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:layout_alignParentRight =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginRight =10px的
        机器人:layout_marginTop =10px的
        机器人:背景=@绘制/ keyboardback>
    < /com.kcs.pd.remote.utils.CustomKeyboardView>
< / RelativeLayout的>

在Java中使用此文件code是:

  mKeyboard =新的键盘(actLiverFunctionTests,R.xml.keyboard);
        mKeyboardView =(CustomKeyboardView)vwParent
                .findViewById(R.id.keyboard_view);        mKeyboardView.setKeyboard(mKeyboard);
        mKeyboardView
                .setOnKeyboardActionListener(新BasicOnKeyboardActionListener(
                        actLiverFunctionTests));

I have a made a custom keyboard for my app which has just a single row of keys. I want to display the keyboard at the centre of the screen rather than in the bottom. Is there any way to do it?

i am using this xml code:

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>

解决方案

you can create below keyboard.xml file

 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.

-->

<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>

call this keyboard at specific position :

    <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>

use this code in java file is as :

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

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

这篇关于在中间显示键盘(或期望的位置)在Android的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆