如何实现特殊的软键盘 [英] How can I implement special soft keyboard

查看:347
本文介绍了如何实现特殊的软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Android应用程序中使用特殊的软键盘,如下所示。





我在软件键盘样本上工作,我编辑了qwerty.xml

 <?xml version =1.0encoding =utf-8?> 
<! -
/ *
**
**版权所有2008,Android开源项目
**
**根据Apache许可证版本2.0(许可证);
**除非符合许可证,否则您不得使用此文件。
**您可以在
**
** http://www.apache.org/licenses/LICENSE-2.0
** $ b获得许可证副本$ b **除非适用法律或书面同意,根据许可证分发的软件
**以按原样分配,b $ b **不附有任何形式的担保或条件,明示或暗示。
**有关许可的具体语言和
**限制,请参阅许可证。
* /
- >

< Keyboard xmlns:android =http://schemas.android.com/apk/res/android
android:keyWidth =10%p
android :horizo​​ntalGap =0px
android:verticalGap =0px
android:keyHeight =6%p
>


<行android:keyWidth =18%p>
< Key android:codes =49android:keyLabel =1android:keyEdgeFlags =left/>
< Key android:codes =50android:keyLabel =2/>
< Key android:codes =51android:keyLabel =3/>
<关键android:codes =52android:keyLabel =4/>
<关键android:codes =53android:keyLabel =5/>
< Key android:codes =54android:keyLabel =6/>
< Key android:codes =55android:keyLabel =7/>
< Key android:codes =56android:keyLabel =8/>
< Key android:codes =57android:keyLabel =9/>
< Key android:codes =48android:keyLabel =0android:keyEdgeFlags =right/>
< Key android:codes = - 5android:keyIcon =@ drawable / sym_keyboard_delete
android:keyWidth =15%pandroid:keyEdgeFlags =right
android :isRepeatable = 真/>
< / Row>
< Row>
< Key android:codes =113android:keyLabel =Qandroid:keyEdgeFlags =left/>
< Key android:codes =119android:keyLabel =W/>
< Key android:codes =101android:keyLabel =E/>
< Key android:codes =114android:keyLabel =R/>
< Key android:codes =116android:keyLabel =T/>
< Key android:codes =121android:keyLabel =Y/>
< Key android:codes =117android:keyLabel =U/>
<关键android:codes =105android:keyLabel =I/>
< Key android:codes =111android:keyLabel =O/>
< Key android:codes =112android:keyLabel =Pandroid:keyEdgeFlags =right/>
< / Row>

< Row>
< Key android:codes =97android:keyLabel =Aandroid:horizo​​ntalGap =5%p
android:keyEdgeFlags =left/>
< Key android:codes =115android:keyLabel =S/>
< Key android:codes =100android:keyLabel =D/>
< Key android:codes =102android:keyLabel =F/>
< Key android:codes =103android:keyLabel =G/>
< Key android:codes =104android:keyLabel =H/>
< Key android:codes =106android:keyLabel =J/>
< Key android:codes =107android:keyLabel =K/>
<关键android:codes =108android:keyLabel =Landroid:keyEdgeFlags =right/>
< / Row>

<行android:keyHeight =8%p>

< Key android:codes =122android:keyLabel =Z/>
< Key android:codes =120android:keyLabel =X/>
< Key android:codes =99android:keyLabel =C/>
< Key android:codes =118android:keyLabel =V/>
< Key android:codes =98android:keyLabel =B/>
< Key android:codes =110android:keyLabel =N/>
< Key android:codes =109android:keyLabel =M/>
< Key android:codes =46android:keyLabel =。
/>
< Key android:codes =32android:keyLabel =SPACE
android:keyWidth =20%pandroid:isRepeatable =true/>
< Key android:codes =10android:keyIcon =@ drawable / sym_keyboard_return
android:keyWidth =20%pandroid:keyEdgeFlags =right/>

< / Row>


< / Keyboard>

我得到以下



< img src =https://i.stack.imgur.com/8Vwl7.pngalt =在此输入图像说明>



忽略第一行,如何我可以使键盘按钮的背景像第一张照片我的意思是我想让我的键盘像第一个具有所有细节的键盘?
如何将Gmail,Hotmail ...添加到我键盘的第一行?
我还想添加一个声音当用户点击任何键,如默认的android键盘
我该怎么办?

解决方案

为键盘创建这样的XML:

 <?xml version =1.0encoding =utf-8?> 
< com.YourKeyboardView xmlns:android =http://schemas.android.com/apk/res/android
android:id =@ + id / keyboard
style =@ style / keyboard_1_style
android:layout_width =fill_parent
android:layout_height =wrap_content>

< /com.YourKeyboardView>

风格如下:

 < style name =keyboard_1_style> 
< item name =android:keyBackground> @ drawable / k1_selector< / item>
< item name =android:keyTextColor>#24B2E7< / item>
< item name =android:background> @android:color / white< / item>
< item name =android:keyPreviewLayout> @ layout / k1_preview< / item>
< / style>

其中

 code>< item name =android:keyBackground> @ drawable / k1_selector< / item> 

用于设置键的背景。

 < item name =android:keyTextColor>#24B2E7< / item> 

用于键的文本颜色。

 < item name =android:background> @android:color / white< / item> 

用于设置整个键盘的背景,

 < item name =android:keyPreviewLayout> @ layout / k1_preview< / item> 

用于设置键预览。



预览布局xml:

 <?xml version =1.0encoding =utf -8\" >?; 
< TextView xmlns:android =http://schemas.android.com/apk/res/android
android:layout_width =wrap_content
android:layout_height =wrap_content
android:textSize =40sp
android:textColor =@ android:color / white
android:gravity =center
android:background =@ drawable / neon_candidate_middle_pressed/>

键之间的空格使用这个



对于 android:background = @ drawable / neon_candidate_middle_pressed它是您要在预览中显示的背景图片。


I want to make special soft keyboard to use it in my android app like the following

I worked on the software keyboard sample and I edited the qwerty.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
/* 
**
** Copyright 2008, The Android Open Source Project
**
** 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.
*/
-->

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:keyWidth="10%p"
    android:horizontalGap="0px"
    android:verticalGap="0px"
    android:keyHeight="6%p"
    >


     <Row   android:keyWidth="18%p">
        <Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left"/>
        <Key android:codes="50" android:keyLabel="2"/>
        <Key android:codes="51" android:keyLabel="3"/>
        <Key android:codes="52" android:keyLabel="4"/>
        <Key android:codes="53" android:keyLabel="5"/>
        <Key android:codes="54" android:keyLabel="6"/>
        <Key android:codes="55" android:keyLabel="7"/>
        <Key android:codes="56" android:keyLabel="8"/>
        <Key android:codes="57" android:keyLabel="9"/>
        <Key android:codes="48" android:keyLabel="0" android:keyEdgeFlags="right"/>
        <Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete" 
                android:keyWidth="15%p" android:keyEdgeFlags="right"
                android:isRepeatable="true"/>
    </Row>
    <Row   >
        <Key android:codes="113" android:keyLabel="Q" android:keyEdgeFlags="left"/>
        <Key android:codes="119" android:keyLabel="W"/>
        <Key android:codes="101" android:keyLabel="E"/>
        <Key android:codes="114" android:keyLabel="R"/>
        <Key android:codes="116" android:keyLabel="T"/>
        <Key android:codes="121" android:keyLabel="Y"/>
        <Key android:codes="117" android:keyLabel="U"/>
        <Key android:codes="105" android:keyLabel="I"/>
        <Key android:codes="111" android:keyLabel="O"/>
        <Key android:codes="112" android:keyLabel="P" android:keyEdgeFlags="right"/>
    </Row>

    <Row    >
        <Key android:codes="97" android:keyLabel="A" android:horizontalGap="5%p" 
                android:keyEdgeFlags="left"/>
        <Key android:codes="115" android:keyLabel="S"/>
        <Key android:codes="100" android:keyLabel="D"/>
        <Key android:codes="102" android:keyLabel="F"/>
        <Key android:codes="103" android:keyLabel="G"/>
        <Key android:codes="104" android:keyLabel="H"/>
        <Key android:codes="106" android:keyLabel="J"/>
        <Key android:codes="107" android:keyLabel="K"/>
        <Key android:codes="108" android:keyLabel="L" android:keyEdgeFlags="right"/>
    </Row>

    <Row    android:keyHeight="8%p">

        <Key android:codes="122" android:keyLabel="Z"/>
        <Key android:codes="120" android:keyLabel="X"/>
        <Key android:codes="99" android:keyLabel="C"/>
        <Key android:codes="118" android:keyLabel="V"/>
        <Key android:codes="98" android:keyLabel="B"/>
        <Key android:codes="110" android:keyLabel="N"/>
        <Key android:codes="109" android:keyLabel="M"/>
        <Key android:codes="46" android:keyLabel="."
              />
        <Key android:codes="32" android:keyLabel="SPACE"
                android:keyWidth="20%p" android:isRepeatable="true"/>
         <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return" 
                android:keyWidth="20%p" android:keyEdgeFlags="right"/>

    </Row>


</Keyboard>

and I get the following

disregard the first row , how can I make the keyboard button background like the first photo I mean I want to make my keyboard like the first one with all details ? How can I add Gmail , Hotmail , ... to the fist row of my keyboard ? I also want to add a sound when the user click on any key like the default android keyboard how can I do that ?

解决方案

Create XML like this for keyboard :

<?xml version="1.0" encoding="utf-8"?>
<com.YourKeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyboard"
    style="@style/keyboard_1_style"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

</com.YourKeyboardView>

And style is as below:

 <style name="keyboard_1_style">
        <item name="android:keyBackground">@drawable/k1_selector</item>
        <item name="android:keyTextColor">#24B2E7</item>
        <item name="android:background">@android:color/white</item>
        <item name="android:keyPreviewLayout">@layout/k1_preview</item>
 </style>

In which

<item name="android:keyBackground">@drawable/k1_selector</item>

is used to set background for key.

<item name="android:keyTextColor">#24B2E7</item> 

is used for text color of key.

<item name="android:background">@android:color/white</item> 

is used to set background of entire keyboard and

<item name="android:keyPreviewLayout">@layout/k1_preview</item>

is uesd to set preview of key.

Preview layout xml :

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="40sp"
    android:textColor="@android:color/white"
    android:gravity="center"
    android:background="@drawable/neon_candidate_middle_pressed"/>

For spaces between keys use this.

And for android:background="@drawable/neon_candidate_middle_pressed" it is background image which you want to show in preview of key.

这篇关于如何实现特殊的软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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