您的位置:首页 > 移动开发 > Android开发

Android 自定义密码键盘

2016-06-24 17:09 381 查看
原来自己很懒没有写过博客,所以样式凑合着看吧,近期因为项目的需求,需要自定义键盘,但是在网上找的都不符合自己的要求,所以索性自己开发,说实话自定义键盘是很简单的,但是在做点击键盘上的按键提示PopupWindow计算位置时真费心,好了废话不多说了,来看代码吧!

一、自定义键盘思路

1.英文字母view(包括大小写)

2.数字键盘view

3.标点符号键盘view

4.特殊键的处理

5.屏蔽原生键盘的显示方法

6.点击键盘有PopupWindow提示

二、界面布局

1.英文字母键盘布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/eng_keyboard"
android:layout_width="fill_parent"
android:layout_height="240dip"
android:layout_weight="5.0"
android:background="@drawable/keyboard_bg"
android:orientation="vertical" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="6.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<Button
android:id="@+id/eng_key_Q"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/q"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_W"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/w"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_E"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/e"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_R"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/r"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_T"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/t"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_Y"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/y"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button

20000
android:id="@+id/eng_key_U"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/u"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_I"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/i"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_O"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/o"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_P"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/p"
android:textColor="@color/white"
android:textSize="22.0sp" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="6.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<ImageView
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:contentDescription="@string/desc" />

<Button
android:id="@+id/eng_key_A"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/a"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_S"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/s"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_D"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/d"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_F"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/f"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_G"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/g"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_H"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/h"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_J"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/j"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_K"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/k"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_L"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/l"
android:textColor="@color/white"
android:textSize="22.0sp" />

<ImageView
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:contentDescription="@string/desc" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="6.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<RelativeLayout
android:id="@+id/eng_key_Shift"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="3.0"
android:background="@drawable/eng_keyboard_button_bg"
android:clickable="true" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/keyboard_shift"
android:contentDescription="@string/desc" />
</RelativeLayout>

<Button
android:id="@+id/eng_key_Z"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/z"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_X"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/x"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_C"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/c"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_V"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/v"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_B"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/b"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_N"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/n"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/eng_key_M"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/m"
android:textColor="@color/white"
android:textSize="22.0sp" />

<RelativeLayout
android:id="@+id/eng_key_Del"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="3.0"
android:background="@drawable/eng_keyboard_button_bg"
android:clickable="true" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/eng_keyboard_delete"
android:contentDescription="@string/desc" />
</RelativeLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="6.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<Button
android:id="@+id/eng_key_123"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/ott"
android:textColor="@color/white"
android:textSize="15.0sp" />

<Button
android:id="@+id/eng_key_Space"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/keyboard_kongge"
android:textColor="@color/white"
android:textSize="15.0sp" />

<Button
android:id="@+id/eng_key_fuhao"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:text="符"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:textColor="@color/white"
android:textSize="15.0sp" />
</LinearLayout>

</LinearLayout>


2.数字键盘

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/num_keyboard"
android:layout_width="fill_parent"
android:layout_height="240dip"
android:layout_alignParentBottom="true"
android:layout_weight="5.0"
android:background="@drawable/keyboard_bg"
android:orientation="vertical" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginTop="5.0dip"
android:layout_weight="3.0"
android:baselineAligned="false"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_margin="1.0dip"
android:layout_weight="1.0"
android:orientation="vertical" >

<ScrollView
android:id="@+id/quick_input_box"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/num_keyboard_scrollbox_bg"
android:scrollbars="none" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<Button
android:id="@+id/num_key_600"
android:layout_width="fill_parent"
android:layout_height="42.0dip"
android:layout_marginLeft="2.0dip"
android:layout_marginRight="1.0dip"
android:background="@drawable/num_keyboard_top_button_bg"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="*"
android:textColor="@color/white"
android:textSize="16.0sp" />

<Button
android:id="@+id/num_key_601"
android:layout_width="fill_parent"
android:layout_height="42.0dip"
android:layout_marginLeft="2.0dip"
android:layout_marginRight="1.0dip"
android:background="@drawable/num_keyboard_mid_button_bg"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="#"
android:textColor="@color/white"
android:textSize="16.0sp" />

<Button
android:id="@+id/num_key_000"
android:layout_width="fill_parent"
android:layout_height="42.0dip"
android:layout_marginLeft="2.0dip"
android:layout_marginRight="1.0dip"
android:background="@drawable/num_keyboard_mid_button_bg"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="+"
android:textColor="@color/white"
android:textSize="16.0sp" />

<Button
android:id="@+id/num_key_002"
android:layout_width="fill_parent"
android:layout_height="42.0dip"
android:layout_marginLeft="2.0dip"
android:layout_marginRight="1.0dip"
android:background="@drawable/num_keyboard_mid_button_bg"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="-"
android:textColor="@color/white"
android:textSize="16.0sp" />

<Button
android:id="@+id/num_key_300"
android:layout_width="fill_parent"
android:layout_height="42.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginLeft="2.0dip"
android:layout_marginRight="1.0dip"
android:background="@drawable/num_keyboard_bottom_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/tzz"
android:textColor="@color/white"
android:textSize="16.0sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>

<LinearLayout
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:orientation="vertical" >

<Button
android:id="@+id/num_key_1"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/one"
android:textColor="@color/white"
android:textSize="26.0sp" />

<Button
android:id="@+id/num_key_4"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/four"
android:textColor="@color/white"
android:textSize="26.0sp" />

<Button
android:id="@+id/num_key_7"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/seven"
android:textColor="@color/white"
android:textSize="26.0sp" />
</LinearLayout>

<LinearLayout
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:orientation="vertical" >

<Button
android:id="@+id/num_key_2"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/two"
android:textColor="@color/white"
android:textSize="26.0sp" />

<Button
android:id="@+id/num_key_5"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/five"
android:textColor="@color/white"
android:textSize="26.0sp" />

<Button
android:id="@+id/num_key_8"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/eight"
android:textColor="@color/white"
android:textSize="26.0sp" />
</LinearLayout>

<LinearLayout
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:orientation="vertical" >

<Button
android:id="@+id/num_key_3"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/three"
android:textColor="@color/white"
android:textSize="26.0sp" />

<Button
android:id="@+id/num_key_6"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/six"
android:textColor="@color/white"
android:textSize="26.0sp" />

<Button
android:id="@+id/num_key_9"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/nine"
android:textColor="@color/white"
android:textSize="26.0sp" />
</LinearLayout>

<LinearLayout
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/num_key_del"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:clickable="true"
android:background="@drawable/eng_keyboard_button_bg" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/num_keyboard_delete"
android:contentDescription="@string/desc" />
</RelativeLayout>

<Button
android:id="@+id/num_key_hide"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="完成"
android:textColor="@color/white"
android:textSize="15.0sp" />

<Button
android:id="@+id/num_key_clear"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="1.0dip"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/keyboard_clear"
android:textColor="@color/white"
android:textSize="15.0sp" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<Button
android:id="@+id/num_key_abc"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_margin="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyeyboard_normal_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/abc"
android:textColor="@color/white"
android:textSize="15.0sp" />

<Button
android:id="@+id/num_key_0"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_margin="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/zero"
android:textColor="@color/white"
android:textSize="26.0sp" />

<Button
android:id="@+id/num_key_fuhao"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_margin="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="符"
android:textColor="@color/white"
android:textSize="15.0sp" />
</LinearLayout>

</LinearLayout>


3.标点符号键盘

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fuhao_keyboard"
android:layout_width="fill_parent"
android:layout_height="240dip"
android:layout_weight="5.0"
android:background="@drawable/keyboard_bg"
android:orientation="vertical" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="6.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<Button
android:id="@+id/fuhao_key_1"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text=","
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_2"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="."
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_3"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="\?"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_4"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="!"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_5"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text=":"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_6"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="/"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_7"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="\@"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_8"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="..."
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_9"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="""
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_10"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text=";"
android:textColor="@color/white"
android:textSize="22.0sp" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="6.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<Button
android:id="@+id/fuhao_key_11"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="\'"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_12"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="~"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_13"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="("
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_14"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text=")"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_15"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="<"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_16"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text=">"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_17"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="*"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_18"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="&"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_19"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="["
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_20"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="1.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="]"
android:textColor="@color/white"
android:textSize="22.0sp" />

</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="6.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<RelativeLayout
android:id="@+id/fuhao_key_Shift"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="3.0"
android:background="@drawable/eng_keyboard_button_bg"
android:clickable="true" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/keyboard_shift"
android:contentDescription="@string/desc" />
</RelativeLayout>

<Button
android:id="@+id/fuhao_key_22"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="\\"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_23"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="`"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_24"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="#"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_25"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="$"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_26"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="%"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_27"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="^"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_28"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="_"
android:textColor="@color/white"
android:textSize="22.0sp" />

<RelativeLayout
android:id="@+id/fuhao_key_Del"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="3.0"
android:background="@drawable/eng_keyboard_button_bg"
android:clickable="true" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/eng_keyboard_delete"
android:contentDescription="@string/desc" />
</RelativeLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="6.0dip"
android:layout_weight="1.0"
android:orientation="horizontal" >

<Button
android:id="@+id/fuhao_key_123"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="3.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/ott"
android:textColor="@color/white"
android:textSize="15.0sp" />

<Button
android:id="@+id/fuhao_key_jia"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="+"
android:textColor="@color/white"
android:textSize="22.0sp" />
<Button
android:id="@+id/fuhao_key_jian"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="-"
android:textColor="@color/white"
android:textSize="22.0sp" />
<Button
android:id="@+id/fuhao_key_deng"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="="
android:textColor="@color/white"
android:textSize="22.0sp" />
<Button
android:id="@+id/fuhao_key_29"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="{"
android:textColor="@color/white"
android:textSize="22.0sp" />
<Button
android:id="@+id/fuhao_key_30"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="}"
android:textColor="@color/white"
android:textSize="22.0sp" />
<Button
android:id="@+id/fuhao_key_shu"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="|"
android:textColor="@color/white"
android:textSize="22.0sp" />

<Button
android:id="@+id/fuhao_key_Space"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="2.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="@string/keyboard_kongge"
android:textColor="@color/white"
android:textSize="15.0sp" />

<Button
android:id="@+id/fuhao_key_abc"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="1.0dip"
android:layout_marginRight="1.0dip"
android:layout_weight="3.0"
android:background="@drawable/eng_keyboard_button_bg"
android:gravity="center"
android:text="ABC"
android:shadowColor="#ff020202"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:textColor="@color/white"
android:textSize="15.0sp" />
</LinearLayout>

</LinearLayout>


4.封装一个keyboardUtils

此类包括:settext    点击键盘时showpop


public class KeyboardUtil implements OnClickListener, OnTouchListener {
private MyKeyBoradView mKeyBoardView = null;
private EditText mEditText;
private Handler mHandler;
private Editable editable;
private int start;
private Button num_key_600;
private Button num_key_601;
private Button num_key_000;
private Button num_key_002;
private Button num_key_300;
private Button num_key_0;
private Button num_key_1;
private Button num_key_2;
private Button num_key_3;
private Button num_key_4;
private Button num_key_5;
private Button num_key_6;
private Button num_key_7;
private Button num_key_8;
private Button num_key_9;
private RelativeLayout num_key_del;
private Button num_key_hide;
private Button num_key_clear;
private Button num_key_abc;
private Button num_key_fuhao;

private Button eng_key_A;
private Button eng_key_B;
private Button eng_key_C;
private Button eng_key_D;
private Button eng_key_E;
private Button eng_key_F;
private Button eng_key_G;
private Button eng_key_H;
private Button eng_key_I;
private Button eng_key_J;
private Button eng_key_K;
private Button eng_key_L;
private Button eng_key_M;
private Button eng_key_N;
private Button eng_key_O;
private Button eng_key_P;
private Button eng_key_Q;
private Button eng_key_R;
private Button eng_key_S;
privat
4000
e Button eng_key_T;
private Button eng_key_U;
private Button eng_key_V;
private Button eng_key_W;
private Button eng_key_X;
private Button eng_key_Y;
private Button eng_key_Z;
private RelativeLayout eng_key_Shift;
private RelativeLayout eng_key_Del;
private Button eng_key_123;
private Button eng_key_Space;
private Button eng_key_fuhao;

private Boolean state = false;
private Boolean mStateFu = false;

private Button fuhao_key_1;
private Button fuhao_key_2;
private Button fuhao_key_3;
private Button fuhao_key_4;
private Button fuhao_key_5;
private Button fuhao_key_6;
private Button fuhao_key_7;
private Button fuhao_key_8;
private Button fuhao_key_9;
private Button fuhao_key_10;
private Button fuhao_key_11;
private Button fuhao_key_12;
private Button fuhao_key_13;
private Button fuhao_key_14;
private Button fuhao_key_15;
private Button fuhao_key_16;
private Button fuhao_key_17;
private Button fuhao_key_18;
private Button fuhao_key_19;
private Button fuhao_key_20;
private RelativeLayout fuhao_key_Shift;
private Button fuhao_key_22;
private Button fuhao_key_23;
private Button fuhao_key_24;
private Button fuhao_key_25;
private Button fuhao_key_26;
private Button fuhao_key_27;
private Button fuhao_key_28;
private RelativeLayout fuhao_key_Del;
private Button fuhao_key_123;
private Button fuhao_key_jia;
private Button fuhao_key_jian;
private Button fuhao_key_deng;
private Button fuhao_key_29;
private Button fuhao_key_30;
private Button fuhao_key_shu;
private Button fuhao_key_Space;
private Button fuhao_key_abc;

private Activity activity;
private Context context;

public KeyboardUtil(Activity activity, Context context, EditText editText,
Handler handler, MyKeyBoradView myKeyBoradView) {
super();
// 初始化输入框
this.mEditText = editText;
// handler
this.mHandler = handler;
// 初始化keyboardView
this.mKeyBoardView = myKeyBoradView;

this.activity = activity;
this.context = context;

// 将输入框实例化成一个editable控件
editable = this.mEditText.getText();

initNumResource();
initEngResource();
initFuResource();
}

private void initFuResource() {
this.fuhao_key_1 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_1);
this.fuhao_key_1.setOnClickListener(this);

this.fuhao_key_2 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_2);
this.fuhao_key_2.setOnClickListener(this);

this.fuhao_key_3 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_3);
this.fuhao_key_3.setOnClickListener(this);

this.fuhao_key_4 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_4);
this.fuhao_key_4.setOnClickListener(this);

this.fuhao_key_5 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_5);
this.fuhao_key_5.setOnClickListener(this);

this.fuhao_key_6 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_6);
this.fuhao_key_6.setOnClickListener(this);

this.fuhao_key_7 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_7);
this.fuhao_key_7.setOnClickListener(this);

this.fuhao_key_8 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_8);
this.fuhao_key_8.setOnClickListener(this);

this.fuhao_key_9 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_9);
this.fuhao_key_9.setOnClickListener(this);

this.fuhao_key_10 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_10);
this.fuhao_key_10.setOnClickListener(this);

this.fuhao_key_11 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_11);
this.fuhao_key_11.setOnClickListener(this);

this.fuhao_key_12 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_12);
this.fuhao_key_12.setOnClickListener(this);

this.fuhao_key_13 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_13);
this.fuhao_key_13.setOnClickListener(this);

this.fuhao_key_14 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_14);
this.fuhao_key_14.setOnClickListener(this);

this.fuhao_key_15 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_15);
this.fuhao_key_15.setOnClickListener(this);

this.fuhao_key_16 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_16);
this.fuhao_key_16.setOnClickListener(this);

this.fuhao_key_17 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_17);
this.fuhao_key_17.setOnClickListener(this);

this.fuhao_key_18 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_18);
this.fuhao_key_18.setOnClickListener(this);

this.fuhao_key_19 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_19);
this.fuhao_key_19.setOnClickListener(this);

this.fuhao_key_20 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_20);
this.fuhao_key_20.setOnClickListener(this);

this.fuhao_key_22 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_22);
this.fuhao_key_22.setOnClickListener(this);

this.fuhao_key_23 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_23);
this.fuhao_key_23.setOnClickListener(this);

this.fuhao_key_24 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_24);
this.fuhao_key_24.setOnClickListener(this);

this.fuhao_key_25 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_25);
this.fuhao_key_25.setOnClickListener(this);

this.fuhao_key_26 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_26);
this.fuhao_key_26.setOnClickListener(this);

this.fuhao_key_27 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_27);
this.fuhao_key_27.setOnClickListener(this);

this.fuhao_key_28 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_28);
this.fuhao_key_28.setOnClickListener(this);

// shift
this.fuhao_key_Shift = (RelativeLayout) mKeyBoardView
.findViewById(R.id.fuhao_key_Shift);
this.fuhao_key_Shift.setOnClickListener(this);

// 删除
this.fuhao_key_Del = (RelativeLayout) mKeyBoardView
.findViewById(R.id.fuhao_key_Del);
this.fuhao_key_Del.setOnClickListener(this);

// 数字123
this.fuhao_key_123 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_123);
this.fuhao_key_123.setOnClickListener(this);

this.fuhao_key_jia = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_jia);
this.fuhao_key_jia.setOnClickListener(this);

this.fuhao_key_jian = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_jian);
this.fuhao_key_jian.setOnClickListener(this);

this.fuhao_key_deng = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_deng);
this.fuhao_key_deng.setOnClickListener(this);

this.fuhao_key_29 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_29);
this.fuhao_key_29.setOnClickListener(this);

this.fuhao_key_30 = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_30);
this.fuhao_key_30.setOnClickListener(this);

this.fuhao_key_shu = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_shu);
this.fuhao_key_shu.setOnClickListener(this);

this.fuhao_key_Space = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_Space);
this.fuhao_key_Space.setOnClickListener(this);

this.fuhao_key_abc = (Button) mKeyBoardView
.findViewById(R.id.fuhao_key_abc);
this.fuhao_key_abc.setOnClickListener(this);
}

// 初始化数字键盘中的元素
private void initNumResource() {
// 数字600
this.num_key_600 = (Button) mKeyBoardView
.findViewById(R.id.num_key_600);
this.num_key_600.setOnClickListener(this);
this.num_key_600.setOnTouchListener(this);

// 数字601
this.num_key_601 = (Button) mKeyBoardView
.findViewById(R.id.num_key_601);
this.num_key_601.setOnClickListener(this);
this.num_key_601.setOnTouchListener(this);

// 数字000
this.num_key_000 = (Button) mKeyBoardView
.findViewById(R.id.num_key_000);
this.num_key_000.setOnClickListener(this);
this.num_key_000.setOnTouchListener(this);

// 数字002
this.num_key_002 = (Button) mKeyBoardView
.findViewById(R.id.num_key_002);
this.num_key_002.setOnClickListener(this);
this.num_key_002.setOnTouchListener(this);

// 数字300
this.num_key_300 = (Button) mKeyBoardView
.findViewById(R.id.num_key_300);
this.num_key_300.setOnClickListener(this);
this.num_key_300.setOnTouchListener(this);

// 数字0
this.num_key_0 = (Button) mKeyBoardView.findViewById(R.id.num_key_0);
this.num_key_0.setOnClickListener(this);
this.num_key_0.setOnTouchListener(this);

// 数字1
this.num_key_1 = (Button) mKeyBoardView.findViewById(R.id.num_key_1);
this.num_key_1.setOnClickListener(this);
this.num_key_1.setOnTouchListener(this);

// 数字2
this.num_key_2 = (Button) mKeyBoardView.findViewById(R.id.num_key_2);
this.num_key_2.setOnClickListener(this);
this.num_key_2.setOnTouchListener(this);

// 数字3
this.num_key_3 = (Button) mKeyBoardView.findViewById(R.id.num_key_3);
this.num_key_3.setOnClickListener(this);
this.num_key_3.setOnTouchListener(this);

// 数字4
this.num_key_4 = (Button) mKeyBoardView.findViewById(R.id.num_key_4);
this.num_key_4.setOnClickListener(this);
this.num_key_4.setOnTouchListener(this);

// 数字5
this.num_key_5 = (Button) mKeyBoardView.findViewById(R.id.num_key_5);
this.num_key_5.setOnClickListener(this);
this.num_key_5.setOnTouchListener(this);

// 数字6
this.num_key_6 = (Button) mKeyBoardView.findViewById(R.id.num_key_6);
this.num_key_6.setOnClickListener(this);
this.num_key_6.setOnTouchListener(this);

// 数字7
this.num_key_7 = (Button) mKeyBoardView.findViewById(R.id.num_key_7);
this.num_key_7.setOnClickListener(this);
this.num_key_7.setOnTouchListener(this);

// 数字8
this.num_key_8 = (Button) mKeyBoardView.findViewById(R.id.num_key_8);
this.num_key_8.setOnClickListener(this);
this.num_key_8.setOnTouchListener(this);

// 数字9
this.num_key_9 = (Button) mKeyBoardView.findViewById(R.id.num_key_9);
this.num_key_9.setOnClickListener(this);
this.num_key_9.setOnTouchListener(this);

// 删除按钮
this.num_key_del = (RelativeLayout) mKeyBoardView
.findViewById(R.id.num_key_del);
this.num_key_del.setOnClickListener(this);
this.num_key_del.setOnTouchListener(this);

// 隐藏按钮
this.num_key_hide = (Button) mKeyBoardView
.findViewById(R.id.num_key_hide);
this.num_key_hide.setOnClickListener(this);
this.num_key_hide.setOnTouchListener(this);

// 清空按钮
this.num_key_clear = (Button) mKeyBoardView
.findViewById(R.id.num_key_clear);
this.num_key_clear.setOnClickListener(this);
this.num_key_clear.setOnTouchListener(this);

// SHIFT abc按钮
this.num_key_abc = (Button) mKeyBoardView
.findViewById(R.id.num_key_abc);
this.num_key_abc.setOnClickListener(this);
this.num_key_abc.setOnTouchListener(this);

this.num_key_fuhao = (Button) mKeyBoardView
.findViewById(R.id.num_key_fuhao);
this.num_key_fuhao.setOnClickListener(this);
this.num_key_fuhao.setOnTouchListener(this);

}

private void initEngResource() {
// 字母A
this.eng_key_A = (Button) mKeyBoardView.findViewById(R.id.eng_key_A);
this.eng_key_A.setOnClickListener(this);

// 字母B
this.eng_key_B = (Button) mKeyBoardView.findViewById(R.id.eng_key_B);
this.eng_key_B.setOnClickListener(this);

// 字母C
this.eng_key_C = (Button) mKeyBoardView.findViewById(R.id.eng_key_C);
this.eng_key_C.setOnClickListener(this);

// 字母D
this.eng_key_D = (Button) mKeyBoardView.findViewById(R.id.eng_key_D);
this.eng_key_D.setOnClickListener(this);

// 字母E
this.eng_key_E = (Button) mKeyBoardView.findViewById(R.id.eng_key_E);
this.eng_key_E.setOnClickListener(this);

// 字母F
this.eng_key_F = (Button) mKeyBoardView.findViewById(R.id.eng_key_F);
this.eng_key_F.setOnClickListener(this);

// 字母G
this.eng_key_G = (Button) mKeyBoardView.findViewById(R.id.eng_key_G);
this.eng_key_G.setOnClickListener(this);

// 字母H
this.eng_key_H = (Button) mKeyBoardView.findViewById(R.id.eng_key_H);
this.eng_key_H.setOnClickListener(this);

// 字母I
this.eng_key_I = (Button) mKeyBoardView.findViewById(R.id.eng_key_I);
this.eng_key_I.setOnClickListener(this);

// 字母J
this.eng_key_J = (Button) mKeyBoardView.findViewById(R.id.eng_key_J);
this.eng_key_J.setOnClickListener(this);

// 字母K
this.eng_key_K = (Button) mKeyBoardView.findViewById(R.id.eng_key_K);
this.eng_key_K.setOnClickListener(this);

// 字母L
this.eng_key_L = (Button) mKeyBoardView.findViewById(R.id.eng_key_L);
this.eng_key_L.setOnClickListener(this);

// 字母M
this.eng_key_M = (Button) mKeyBoardView.findViewById(R.id.eng_key_M);
this.eng_key_M.setOnClickListener(this);

// 字母N
this.eng_key_N = (Button) mKeyBoardView.findViewById(R.id.eng_key_N);
this.eng_key_N.setOnClickListener(this);

// 字母O
this.eng_key_O = (Button) mKeyBoardView.findViewById(R.id.eng_key_O);
this.eng_key_O.setOnClickListener(this);

// 字母P
this.eng_key_P = (Button) mKeyBoardView.findViewById(R.id.eng_key_P);
this.eng_key_P.setOnClickListener(this);

// 字母Q
this.eng_key_Q = (Button) mKeyBoardView.findViewById(R.id.eng_key_Q);
this.eng_key_Q.setOnClickListener(this);

// 字母R
this.eng_key_R = (Button) mKeyBoardView.findViewById(R.id.eng_key_R);
this.eng_key_R.setOnClickListener(this);

// 字母S
this.eng_key_S = (Button) mKeyBoardView.findViewById(R.id.eng_key_S);
this.eng_key_S.setOnClickListener(this);

// 字母T
this.eng_key_T = (Button) mKeyBoardView.findViewById(R.id.eng_key_T);
this.eng_key_T.setOnClickListener(this);

// 字母U
this.eng_key_U = (Button) mKeyBoardView.findViewById(R.id.eng_key_U);
this.eng_key_U.setOnClickListener(this);

// 字母V
this.eng_key_V = (Button) mKeyBoardView.findViewById(R.id.eng_key_V);
this.eng_key_V.setOnClickListener(this);

// 字母W
this.eng_key_W = (Button) mKeyBoardView.findViewById(R.id.eng_key_W);
this.eng_key_W.setOnClickListener(this);

// 字母X
this.eng_key_X = (Button) mKeyBoardView.findViewById(R.id.eng_key_X);
this.eng_key_X.setOnClickListener(this);

// 字母Y
this.eng_key_Y = (Button) mKeyBoardView.findViewById(R.id.eng_key_Y);
this.eng_key_Y.setOnClickListener(this);

// 字母Z
this.eng_key_Z = (Button) mKeyBoardView.findViewById(R.id.eng_key_Z);
this.eng_key_Z.setOnClickListener(this);

// shift
this.eng_key_Shift = (RelativeLayout) mKeyBoardView
.findViewById(R.id.eng_key_Shift);
this.eng_key_Shift.setOnClickListener(this);

// 删除
this.eng_key_Del = (RelativeLayout) mKeyBoardView
.findViewById(R.id.eng_key_Del);
this.eng_key_Del.setOnClickListener(this);

// 数字123
this.eng_key_123 = (Button) mKeyBoardView
.findViewById(R.id.eng_key_123);
this.eng_key_123.setOnClickListener(this);

// 空格键
this.eng_key_Space = (Button) mKeyBoardView
.findViewById(R.id.eng_key_Space);
this.eng_key_Space.setOnClickListener(this);

this.eng_key_fuhao = (Button) mKeyBoardView
.findViewById(R.id.eng_key_fuhao);
this.eng_key_fuhao.setOnClickListener(this);
}

private void showText(String text) {
editable.insert(start, text);
}

// 按钮点击事件
@Override
public void onClick(View v) {
start = this.mEditText.getSelectionStart();
switch (v.getId()) {
case R.id.num_key_0:
showText(num_key_0.getText().toString());
break;

case R.id.num_key_1:
showText(num_key_1.getText().toString());
break;

case R.id.num_key_2:
showText(num_key_2.getText().toString());
break;

case R.id.num_key_3:
showText(num_key_3.getText().toString());
break;

case R.id.num_key_4:
showText(num_key_4.getText().toString());
break;

case R.id.num_key_5:
showText(num_key_5.getText().toString());
break;

case R.id.num_key_6:
showText(num_key_6.getText().toString());
break;

case R.id.num_key_7:
showText(num_key_7.getText().toString());
break;

case R.id.num_key_8:
showText(num_key_8.getText().toString());
break;

case R.id.num_key_9:
showText(num_key_9.getText().toString());
break;

case R.id.num_key_600:
showText(num_key_600.getText().toString());
break;

case R.id.num_key_601:
showText(num_key_601.getText().toString());
break;

case R.id.num_key_000:
showText(num_key_000.getText().toString());
break;

case R.id.num_key_002:
showText(num_key_002.getText().toString());
break;

case R.id.num_key_300:
showText(num_key_300.getText().toString());
break;

case R.id.num_key_del:
deleteText();
break;

case R.id.num_key_hide:
mHandler.sendEmptyMessage(22);
break;

case R.id.num_key_clear:
editable.clear();
break;

case R.id.num_key_abc:
mHandler.sendEmptyMessage(21);
break;

case R.id.num_key_fuhao:
mHandler.sendEmptyMessage(23);
break;

case R.id.eng_key_A:
showText(eng_key_A.getText().toString());
break;

case R.id.eng_key_B:
showText(eng_key_B.getText().toString());
break;

case R.id.eng_key_C:
showText(eng_key_C.getText().toString());
break;

case R.id.eng_key_D:
showText(eng_key_D.getText().toString());
break;

case R.id.eng_key_E:
showText(eng_key_E.getText().toString());
break;

case R.id.eng_key_F:
showText(eng_key_F.getText().toString());
break;

case R.id.eng_key_G:
showText(eng_key_G.getText().toString());
break;

case R.id.eng_key_H:
showText(eng_key_H.getText().toString());
break;

case R.id.eng_key_I:
showText(eng_key_I.getText().toString());
break;

case R.id.eng_key_J:
showText(eng_key_J.getText().toString());
break;

case R.id.eng_key_K:
showText(eng_key_K.getText().toString());
break;

case R.id.eng_key_L:
showText(eng_key_L.getText().toString());
break;

case R.id.eng_key_M:
showText(eng_key_M.getText().toString());
break;

case R.id.eng_key_N:
showText(eng_key_N.getText().toString());
break;

case R.id.eng_key_O:
showText(eng_key_O.getText().toString());
break;

case R.id.eng_key_P:
showText(eng_key_P.getText().toString());
break;

case R.id.eng_key_Q:
showText(eng_key_Q.getText().toString());
break;

case R.id.eng_key_R:
showText(eng_key_R.getText().toString());
break;

case R.id.eng_key_S:
showText(eng_key_S.getText().toString());
break;

case R.id.eng_key_T:
showText(eng_key_T.getText().toString());
break;

case R.id.eng_key_U:
showText(eng_key_U.getText().toString());
break;

case R.id.eng_key_V:
showText(eng_key_V.getText().toString());
break;

case R.id.eng_key_W:
showText(eng_key_W.getText().toString());
break;

case R.id.eng_key_X:
showText(eng_key_X.getText().toString());
break;

case R.id.eng_key_Y:
showText(eng_key_Y.getText().toString());
break;

case R.id.eng_key_Z:
showText(eng_key_Z.getText().toString());
break;

case R.id.eng_key_Shift:
initABC();
break;

case R.id.eng_key_Del:
deleteText();
break;

case R.id.eng_key_123:
mHandler.sendEmptyMessage(20);
break;

case R.id.eng_key_Space:
showText(" ");
break;

case R.id.eng_key_fuhao:
mHandler.sendEmptyMessage(24);
break;
case R.id.fuhao_key_1:
showText(fuhao_key_1.getText().toString());
break;
case R.id.fuhao_key_2:
showText(fuhao_key_2.getText().toString());
break;
case R.id.fuhao_key_3:
showText(fuhao_key_3.getText().toString());
break;
case R.id.fuhao_key_4:
showText(fuhao_key_4.getText().toString());
break;
case R.id.fuhao_key_5:
showText(fuhao_key_5.getText().toString());
break;
case R.id.fuhao_key_6:
showText(fuhao_key_6.getText().toString());
break;
case R.id.fuhao_key_7:
showText(fuhao_key_7.getText().toString());
break;
case R.id.fuhao_key_8:
showText(fuhao_key_8.getText().toString());
break;
case R.id.fuhao_key_9:
showText(fuhao_key_9.getText().toString());
break;
case R.id.fuhao_key_10:
showText(fuhao_key_10.getText().toString());
break;
case R.id.fuhao_key_11:
showText(fuhao_key_11.getText().toString());
break;
case R.id.fuhao_key_12:
showText(fuhao_key_12.getText().toString());
break;
case R.id.fuhao_key_13:
showText(fuhao_key_13.getText().toString());
break;
case R.id.fuhao_key_14:
showText(fuhao_key_14.getText().toString());
break;
case R.id.fuhao_key_15:
showText(fuhao_key_15.getText().toString());
break;
case R.id.fuhao_key_16:
showText(fuhao_key_16.getText().toString());
break;
case R.id.fuhao_key_17:
showText(fuhao_key_17.getText().toString());
break;
case R.id.fuhao_key_18:
showText(fuhao_key_18.getText().toString());
break;
case R.id.fuhao_key_19:
showText(fuhao_key_19.getText().toString());
break;
case R.id.fuhao_key_20:
showText(fuhao_key_20.getText().toString());
break;
case R.id.fuhao_key_Shift:
initFU();
break;
case R.id.fuhao_key_22:
showText(fuhao_key_22.getText().toString());
break;
case R.id.fuhao_key_23:
showText(fuhao_key_23.getText().toString());
break;
case R.id.fuhao_key_24:
showText(fuhao_key_24.getText().toString());
break;
case R.id.fuhao_key_25:
showText(fuhao_key_25.getText().toString());
break;
case R.id.fuhao_key_26:
showText(fuhao_key_26.getText().toString());
break;
case R.id.fuhao_key_27:
showText(fuhao_key_27.getText().toString());
break;
case R.id.fuhao_key_28:
showText(fuhao_key_28.getText().toString());
break;
case R.id.fuhao_key_Del:
deleteText();
break;
case R.id.fuhao_key_123:
mHandler.sendEmptyMessage(25);
break;
case R.id.fuhao_key_jia:
showText(fuhao_key_jia.getText().toString());
break;
case R.id.fuhao_key_jian:
showText(fuhao_key_jian.getText().toString());
break;
case R.id.fuhao_key_deng:
showText(fuhao_key_deng.getText().toString());
break;
case R.id.fuhao_key_29:
showText(fuhao_key_29.getText().toString());
break;
case R.id.fuhao_key_30:
showText(fuhao_key_30.getText().toString());
break;
case R.id.fuhao_key_shu:
showText(fuhao_key_shu.getText().toString());
break;
case R.id.fuhao_key_Space:
showText(" ");
break;
case R.id.fuhao_key_abc:
mHandler.sendEmptyMessage(26);
break;
default:
break;
}
}

private void initFU() {
if (mStateFu == false) {
fuhao_key_1.setText(",");
fuhao_key_2.setText("。");
fuhao_key_3.setText("?");
fuhao_key_4.setText("!");
fuhao_key_5.setText(":");
fuhao_key_6.setText("/");
fuhao_key_7.setText("@");
fuhao_key_8.setText("……");
fuhao_key_9.setText("”");
fuhao_key_10.setText(";");
fuhao_key_11.setText("‘");
fuhao_key_12.setText("~");
fuhao_key_13.setText("(");
fuhao_key_14.setText(")");
fuhao_key_15.setText("《");
fuhao_key_16.setText("》");
fuhao_key_17.setText("*");
fuhao_key_18.setText("&");
fuhao_key_19.setText("[");
fuhao_key_20.setText("]");
fuhao_key_22.setText("\");
fuhao_key_23.setText("`");
fuhao_key_24.setText("#");
fuhao_key_25.setText("$");
fuhao_key_26.setText("%");
fuhao_key_27.setText("︿");
fuhao_key_28.setText("_");
fuhao_key_jia.setText("+");
fuhao_key_jian.setText("-");
fuhao_key_deng.setText("=");
fuhao_key_29.setText("{");
fuhao_key_30.setText("}");
fuhao_key_shu.setText("|");
mStateFu = true;
} else {
fuhao_key_1.setText(",");
fuhao_key_2.setText(".");
fuhao_key_3.setText("?");
fuhao_key_4.setText("!");
fuhao_key_5.setText(":");
fuhao_key_6.setText("/");
fuhao_key_7.setText("@");
fuhao_key_8.setText("...");
fuhao_key_9.setText("\"");
fuhao_key_10.setText(";");
fuhao_key_11.setText("'");
fuhao_key_12.setText("~");
fuhao_key_13.setText("(");
fuhao_key_14.setText(")");
fuhao_key_15.setText("<");
fuhao_key_16.setText(">");
fuhao_key_17.setText("*");
fuhao_key_18.setText("&");
fuhao_key_19.setText("[");
fuhao_key_20.setText("]");
fuhao_key_22.setText("\\");
fuhao_key_23.setText("`");
fuhao_key_24.setText("#");
fuhao_key_25.setText("$");
fuhao_key_26.setText("%");
fuhao_key_27.setText("^");
fuhao_key_28.setText("_");
fuhao_key_jia.setText("+");
fuhao_key_jian.setText("-");
fuhao_key_deng.setText("=");
fuhao_key_29.setText("{");
fuhao_key_30.setText("}");
fuhao_key_shu.setText("|");
mStateFu = false;
}
}

// 用于shift切换大小写字母
private void initABC() {
if (state == false) {
eng_key_A.setText("A");
eng_key_B.setText("B");
eng_key_C.setText("B");
eng_key_D.setText("D");
eng_key_E.setText("E");
eng_key_F.setText("F");
eng_key_G.setText("G");
eng_key_H.setText("H");
eng_key_I.setText("I");
eng_key_J.setText("J");
eng_key_K.setText("K");
eng_key_L.setText("L");
eng_key_M.setText("M");
eng_key_N.setText("N");
eng_key_O.setText("O");
eng_key_P.setText("P");
eng_key_Q.setText("Q");
eng_key_R.setText("R");
eng_key_S.setText("S");
eng_key_T.setText("T");
eng_key_U.setText("U");
eng_key_V.setText("V");
eng_key_W.setText("W");
eng_key_X.setText("X");
eng_key_Y.setText("Y");
eng_key_Z.setText("Z");
state = true;
} else {
eng_key_A.setText("a");
eng_key_B.setText("b");
eng_key_C.setText("c");
eng_key_D.setText("d");
eng_key_E.setText("e");
eng_key_F.setText("f");
eng_key_G.setText("g");
eng_key_H.setText("h");
eng_key_I.setText("i");
eng_key_J.setText("j");
eng_key_K.setText("k");
eng_key_L.setText("l");
eng_key_M.setText("m");
eng_key_N.setText("n");
eng_key_O.setText("o");
eng_key_P.setText("p");
eng_key_Q.setText("q");
eng_key_R.setText("r");
eng_key_S.setText("s");
eng_key_T.setText("t");
eng_key_U.setText("u");
eng_key_V.setText("v");
eng_key_W.setText("w");
eng_key_X.setText("x");
eng_key_Y.setText("y");
eng_key_Z.setText("z");
state = false;
}
}

// 删除方法
private void deleteText() {
if (editable != null && editable.length() > 0) {
if (start > 0) {
editable.delete(start - 1, start);
}
}
}

private PopupWindow popupWindow;
private void showPop(int id ,String text){

LayoutInflater layoutInflater = LayoutInflater.from(context);
View popupView = layoutInflater.inflate(R.layout.key_pop, null);
popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
TextView textView = (TextView) popupView.findViewById(R.id.pop);
textView.setText(text);

//          if (id == R.id.eng_key_one || id == R.id.eng_key_Q || id == R.id.fuhao_key_19
//                  || id == R.id.fuhao_key_jian || id == R.id.fuhao_key_2) {
//              textView.setBackgroundResource(R.drawable.left_pop);
//          }
//          if (id == R.id.eng_key_zero || id == R.id.eng_key_P || id == R.id.fuhao_key_deng
//                  || id == R.id.fuhao_key_shu) {
//              textView.setBackgroundResource(R.drawable.right_pop);
//          }

int popupWidth = popupView.getMeasuredWidth();
int popupHeight =  popupView.getMeasuredHeight();

int[] location = new int[2];
activity.findViewById(id).getLocationOnScreen(location);

popupWindow.showAtLocation(activity.findViewById(id), Gravity.NO_GRAVITY,
(location[0] + (activity.findViewById(id).getWidth())/2)-popupWidth/2, location[1] - popupHeight/2);

popupWindow.setOutsideTouchable(true);
}

@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
start = this.mEditText.getSelectionStart();
switch (arg1.getAction()) {

case MotionEvent.ACTION_DOWN:
showPop(arg0.getId(), ((Button) mKeyBoardView.findViewById(arg0.getId())).getText().toString());
break;
case MotionEvent.ACTION_UP:
if (popupWindow != null) {
popupWindow.dismiss();
}
break;
default:
break;
}
return false;

}
}


5.特殊键的处理

返回键,当按返回键时,首先隐藏自定义键盘,然后退出程序


6.屏蔽原生键盘的弹出,显示自定义键盘

说明:隐藏原生键盘的方法有两个判断的原因是:4.0用反射调用setShowSoftInputOnFocus方法,此方法为4.0新增,2.3仍用 mEtInput.setInputType(InputType.TYPE_NULL)

private void disableSysKeyboard() {
if (android.os.Build.VERSION.SDK_INT <= 10) {
code_input.setInputType(InputType.TYPE_NULL);
} else {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
try {
Class<EditText> cls = EditText.class;
Method setShowSoftInputOnFocus;
setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
setShowSoftInputOnFocus.setAccessible(true);
setShowSoftInputOnFocus.invoke(code_input, false);
} catch (Exception e) {
e.printStackTrace();
}
}
}


7.点击键盘显示PopupWindow

在我的demo中,显示PopupWindow的方法放在了ontouch里面,dowm的时候显示,up的时候PopupWindow消失


三、demo截图

> 1.![数字键盘](http://img.blog.csdn.net/20160627111339550)
> 2.![字母键盘](http://img.blog.csdn.net/20160627111403934)
> 3.![符号键盘](http://img.blog.csdn.net/20160627111426044)
> 4.![点击数字键盘显示pop](http://img.blog.csdn.net/20160627111453091)


四、demo说明

1.只有数据键盘界面添加了pop的显示,如果别的界面有需求,自己加上
2.在数字键盘上有一个问题,当触碰到键盘的时候,显示pop,但是ed上没有输入上数字,原因:showtext的方法在onclick里面调用
解决办法:showtext放到ontouch方法中的down事件中即可

至于为什么?自己去看onclick和ontouch的源码,搞清楚执行顺序,你就明白了,哈哈哈!!!!


五、项目下载地址

http://download.csdn.net/detail/weinan_w/9560738
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 自定义键盘