我如何能实施特别软键盘 [英] How can I implement special soft keyboard

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

问题描述

我要作出特别的软键盘来使用它在我的Andr​​oid应用程序,如以下

我的工作是软件键盘的样品和我编辑的qwerty.xml

 < XML版本=1.0编码=UTF-8&GT?;
<! - 
/ *
**
**版权所有2008年,Android开源项目
**
** Apache许可证下授权,版本2.0(以下简称许可证);
**你可能不使用这个文件除了在遵守许可。
**您可以在获得许可证的副本
**
** http://www.apache.org/licenses/LICENSE-2.0
**
**除非适用法律要求或书面同意,软件
**许可证下发布分布在原样的基础上,
**无担保或任何形式的条件,无论是EX preSS或暗示的保证。
**查看许可证的特定语言的管理权限和
**许可下限制。
* /
 - >

<键盘的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:keyWidth =10%P
    机器人:horizo​​ntalGap =0px
    安卓的verticalGap =0px
    机器人:keyHeight =6%P
    >


     <行的android:keyWidth =18%P>
        <关键的android:codeS =49机器人:keyLabel =1机器人:keyEdgeFlags =左/>
        <关键的android:codeS =50机器人:keyLabel =2/>
        <关键的android:codeS =51机器人:keyLabel =3/>
        <关键的android:codeS =52机器人:keyLabel =4/>
        <关键的android:codeS =53机器人:keyLabel =5/>
        <关键的android:codeS =54机器人:keyLabel =6/>
        <关键的android:codeS =55机器人:keyLabel =7/>
        <关键的android:codeS =56机器人:keyLabel =8/>
        <关键的android:codeS =57机器人:keyLabel =9/>
        <关键的android:codeS =48机器人:keyLabel =0安卓keyEdgeFlags =右/>
        <关键的android:codeS = -  5安卓keyIcon =@可绘制/ sym_keyboard_delete
                机器人:keyWidth =15%的对机​​器人:keyEdgeFlags =右
                机器人:isRepeatable =真/>
    < /行>
    <行>
        <关键的android:codeS =113机器人:keyLabel =Q机器人:keyEdgeFlags =左/>
        <关键的android:codeS =119机器人:keyLabel =W/>
        <关键的android:codeS =101机器人:keyLabel =E/>
        <关键的android:codeS =114机器人:keyLabel =R/>
        <关键的android:codeS =116机器人:keyLabel =T/>
        <关键的android:codeS =121机器人:keyLabel =Y/>
        <关键的android:codeS =117机器人:keyLabel =U/>
        <关键的android:codeS =105机器人:keyLabel =我/>
        <关键的android:codeS =111机器人:keyLabel =O/>
        <关键的android:codeS =112机器人:keyLabel =P的Andr​​oid版本:keyEdgeFlags =右/>
    < /行>

    <行>
        <关键的android:codeS =97机器人:keyLabel =A的Andr​​oid版本:horizo​​ntalGap =5%P
                机器人:keyEdgeFlags =左/>
        <关键的android:codeS =115机器人:keyLabel =S/>
        <关键的android:codeS =100机器人:keyLabel =D/>
        <关键的android:codeS =102机器人:keyLabel =F/>
        <关键的android:codeS =103机器人:keyLabel =G/>
        <关键的android:codeS =104机器人:keyLabel =H/>
        <关键的android:codeS =106机器人:keyLabel =J/>
        <关键的android:codeS =107机器人:keyLabel =K/>
        <关键的android:codeS =108机器人:keyLabel =L的Andr​​oid版本:keyEdgeFlags =右/>
    < /行>

    <行的android:keyHeight =8%P>

        <关键的android:codeS =122机器人:keyLabel =Z/>
        <关键的android:codeS =120机器人:keyLabel =X/>
        <关键的android:codeS =99机器人:keyLabel =C/>
        <关键的android:codeS =118机器人:keyLabel =V/>
        <关键的android:codeS =98机器人:keyLabel =B/>
        <关键的android:codeS =110机器人:keyLabel =N/>
        <关键的android:codeS =109机器人:keyLabel =M/>
        <关键的android:codeS =46机器人:keyLabel =。
              />
        <关键的android:codeS =32机器人:keyLabel =SPACE
                机器人:keyWidth =20%P机器人:isRepeatable =真/>
         <关键的android:codeS =10机器人:keyIcon =@可绘制/ sym_keyboard_return
                机器人:keyWidth =20%P机器人:keyEdgeFlags =右/>

    < /行>


< /键盘>
 

和我得到了以下

忽略的第一行,我怎样才能使键盘按钮的背景,如第一张照片我的意思是我想让我的键盘就像第一个与所有的细节? 我如何添加的Gmail,Hotmail的,......我的键盘的拳头行? 我也想添加声音,当用户点击喜欢默认的Andr​​oid键盘任意键 我该怎么办呢?

解决方案

创建XML这样的键盘:

 < XML版本=1.0编码=UTF-8&GT?;
< com.YourKeyboardView的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID /键盘
    风格=@风格/ keyboard_1_style
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>

< /com.YourKeyboardView>
 

和样式如下:

 <样式名称=keyboard_1_style>
        <项目名称=机器人:keyBackground> @可绘制/ k1_selector< /项目>
        <项目名称=机器人:keyTextColor>#24B2E7< /项目>
        <项目名称=机器人:背景> @android:彩色/白< /项目>
        <项目名称=机器人:关键previewLayout> @布局/ k1_ preVIEW< /项目>
 < /风格>
 

在其中

 <项目名称=机器人:keyBackground> @可绘制/ k1_selector< /项目>
 

用来设置背景的关键。

 <项目名称=机器人:keyTextColor>#24B2E7< /项目>
 

用于密钥的文本颜色。

 <项目名称=机器人:背景> @android:彩色/白< /项目>
 

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

 <项目名称=机器人:关键previewLayout> @布局/ k1_ preVIEW< /项目>
 

被uesd设置键preVIEW。

preVIEW布局的xml:

 < XML版本=1.0编码=UTF-8&GT?;
< TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:TEXTSIZE =40SP
    机器人:文字颜色=@机器人:彩色/白
    机器人:重力=中心
    机器人:背景=@可绘制/ neon_candidate_middle_ pressed/>
 

有关键之间的空间使用<一个href="http://developer.android.com/reference/android/inputmethodservice/Keyboard.Key.html#attr_android%3ahorizontalGap">this.

和为安卓背景=@可绘制/ neon_candidate_middle_ pressed是要在关键的preVIEW显示背景图片<。 / P>

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天全站免登陆