前一段时间,由于业务需要,了解了一下关于自定义键盘的相关操作。
实现方式
主要是两种实现方式,我这里就以一个数字键盘来作为实现。
方式一效果图
方式二效果图
方式一
该方式是使用我们最原始的方式,自己画UI ,然后去实现监听事件,
这种方式我们就不过多废话,先来看一下自己画的 xml ,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_60"
android:orientation="horizontal">
<TextView
android:id="@+id/kb_tv_1"
style="@style/keyboard_text_style"
android:text="1" />
<View style="@style/keyboard_ver_line" />
<TextView
android:id="@+id/kb_tv_2"
style="@style/keyboard_text_style"
android:text="2" />
<View style="@style/keyboard_ver_line" />
<TextView
android:id="@+id/kb_tv_3"
style="@style/keyboard_text_style"
android:text="3" />
</LinearLayout>
<View style="@style/keyboard_hor_line" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_60"
android:orientation="horizontal">
<TextView
android:id="@+id/kb_tv_4"
style="@style/keyboard_text_style"
android:text="4" />
<View style="@style/keyboard_ver_line" />
<TextView
android:id="@+id/kb_tv_5"
style="@style/keyboard_text_style"
android:text="5" />
<View style="@style/keyboard_ver_line" />
<TextView
android:id="@+id/kb_tv_6"
style="@style/keyboard_text_style"
android:text="6" />
</LinearLayout>
<View style="@style/keyboard_hor_line" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_60"
android:orientation="horizontal">
<TextView
android:id="@+id/kb_tv_7"
style="@style/keyboard_text_style"
android:text="7" />
<View style="@style/keyboard_ver_line" />
<TextView
android:id="@+id/kb_tv_8"
style=