当前位置: 首页 > wzjs >正文

wordpress建站要用模板吗吉林市网站建设优化

wordpress建站要用模板吗,吉林市网站建设优化,网站开发专员的面试题,绍兴网站制作套餐在 Android 应用中,系统默认的键盘可能无法满足特定需求(如仅支持数字输入、自定义布局等)。本文将详细介绍如何实现一个自定义数字键盘,并提供完整的代码示例。 实现步骤 1. 创建自定义键盘布局 首先,我们需要定义一…

在 Android 应用中,系统默认的键盘可能无法满足特定需求(如仅支持数字输入、自定义布局等)。本文将详细介绍如何实现一个自定义数字键盘,并提供完整的代码示例。

实现步骤
1. 创建自定义键盘布局
首先,我们需要定义一个自定义键盘的布局文件。在 res/xml 目录下创建一个 XML 文件(例如 number_keyboard.xml),用于描述键盘的按键布局。

文件:res/xml/number_keyboard.xml

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"android:keyWidth="20%p"android:keyHeight="60dp"android:horizontalGap="5dp"android:verticalGap="5dp"><!-- 第一行:1, 2, 3 --><Row><Key android:codes="49" android:keyLabel="1" /><Key android:codes="50" android:keyLabel="2" /><Key android:codes="51" android:keyLabel="3" /></Row><!-- 第二行:4, 5, 6 --><Row><Key android:codes="52" android:keyLabel="4" /><Key android:codes="53" android:keyLabel="5" /><Key android:codes="54" android:keyLabel="6" /></Row><!-- 第三行:7, 8, 9 --><Row><Key android:codes="55" android:keyLabel="7" /><Key android:codes="56" android:keyLabel="8" /><Key android:codes="57" android:keyLabel="9" /></Row><!-- 第四行:删除键, 0, 完成键 --><Row><Key android:codes="-5" android:keyLabel="删除" /><Key android:codes="48" android:keyLabel="0" /><Key android:codes="-1" android:keyLabel="完成" /></Row>
</Keyboard>

参数说明:
android:keyWidth:按键的宽度(20%p 表示占父容器宽度的 20%)。

android:keyHeight:按键的高度。

android:codes:按键的键值(如 49 对应字符 ‘1’)。

android:keyLabel:按键上显示的文本。

2. 在布局文件中添加 KeyboardView
接下来,在 Activity 的布局文件中添加一个 KeyboardView,用于显示自定义键盘。

文件:res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="16dp"><!-- 输入框 --><EditTextandroid:id="@+id/editText"android:layout_width="match_parent"android:layout_height="wrap_content"android:inputType="number"android:hint="请输入数字" /><!-- 自定义键盘 --><android.inputmethodservice.KeyboardViewandroid:id="@+id/keyboardView"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="16dp" />
</LinearLayout>

3. 在 Activity 中实现键盘逻辑
在 Activity 中加载自定义键盘,并处理按键事件。

文件:MainActivity.java

import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.os.Bundle;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity {private EditText editText;private KeyboardView keyboardView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 初始化视图editText = findViewById(R.id.editText);keyboardView = findViewById(R.id.keyboardView);// 加载自定义键盘布局Keyboard keyboard = new Keyboard(this, R.xml.number_keyboard);keyboardView.setKeyboard(keyboard);// 设置键盘事件监听器keyboardView.setOnKeyboardActionListener(new KeyboardView.OnKeyboardActionListener() {@Overridepublic void onKey(int primaryCode, int[] keyCodes) {// 处理按键事件switch (primaryCode) {case Keyboard.KEYCODE_DELETE: // 删除键String currentText = editText.getText().toString();if (currentText.length() > 0) {editText.setText(currentText.substring(0, currentText.length() - 1));}break;case Keyboard.KEYCODE_DONE: // 完成键finish(); // 关闭当前 Activitybreak;default: // 数字键char code = (char) primaryCode;editText.append(String.valueOf(code));break;}}@Overridepublic void onPress(int primaryCode) {// 按键按下时的操作(可选)}@Overridepublic void onRelease(int primaryCode) {// 按键释放时的操作(可选)}@Overridepublic void onText(CharSequence text) {// 处理文本输入(可选)}@Overridepublic void swipeLeft() {// 处理左滑(可选)}@Overridepublic void swipeRight() {// 处理右滑(可选)}@Overridepublic void swipeDown() {// 处理下滑(可选)}@Overridepublic void swipeUp() {// 处理上滑(可选)}});}
}

4. 运行效果
运行应用后,你会看到一个自定义的数字键盘:

点击数字键,输入框会显示对应的数字。

点击删除键,会删除最后一个字符。

点击完成键,会关闭当前 Activity。

5. 关键点解析
KeyboardView:

用于显示自定义键盘。
必须使用完整的包名 android.inputmethodservice.KeyboardView

android:codes:

定义按键的键值。

支持自定义值(如 -5 表示删除键,-1 表示完成键)。

OnKeyboardActionListener:

监听键盘事件。

主要实现 onKey 方法,处理按键逻辑。


文章转载自:

http://FccNscof.mxLwL.cn
http://VsVulwwl.mxLwL.cn
http://lgNbN8Xn.mxLwL.cn
http://U5RkSoET.mxLwL.cn
http://p3GdyqTX.mxLwL.cn
http://pTkcU2T7.mxLwL.cn
http://gOqEnEqo.mxLwL.cn
http://OByUIpGw.mxLwL.cn
http://sKa1sjEk.mxLwL.cn
http://reIMFoR0.mxLwL.cn
http://ux12sVio.mxLwL.cn
http://QtMby7VE.mxLwL.cn
http://NMq01AkW.mxLwL.cn
http://vmOSkRzx.mxLwL.cn
http://o09m9S9P.mxLwL.cn
http://hQDdVQQ5.mxLwL.cn
http://41NHFZdc.mxLwL.cn
http://pLkVrFBX.mxLwL.cn
http://FVa1Q9sI.mxLwL.cn
http://zaYz1Ydy.mxLwL.cn
http://ucpaDMrq.mxLwL.cn
http://3WQdfZyq.mxLwL.cn
http://CJmoztzm.mxLwL.cn
http://jbIwHFLV.mxLwL.cn
http://bJEEClPK.mxLwL.cn
http://B11AiMR7.mxLwL.cn
http://fj8qSgI7.mxLwL.cn
http://IEZTaMOP.mxLwL.cn
http://MSRdZJLf.mxLwL.cn
http://8usG8IBS.mxLwL.cn
http://www.dtcms.com/wzjs/662403.html

相关文章:

  • 最好的响应式网站有哪些石家庄 网站建设 15369356722
  • 潮州哪里做网站wordpress 批量换
  • html做静态网站苏州网站建设一条龙
  • wordpress获取当前网址关键词怎么优化到百度首页
  • 黑龙江省建设监理协会网站手机网站免费做app
  • 百度搜不倒公司网站wordpress时间插件下载地址
  • 青岛网站建设方案案例商城类网站总体功能策划
  • 东莞建站网站建设产品推广wordpress 外链转内链
  • 高端品牌网站建设建议公司网站建站哪个系统好用
  • 电子商务网站的建设及规划推广小程序拿佣金
  • 校园网站管理系统梅州站改造高铁站
  • 自助建站视频网站建设小程序怎么挂失
  • 嘉兴企业网站模板连锁销售网站制作
  • 深圳网站建设有免费的吗网页制作与网站建设06627
  • 建设手机网站平台江西建设银行分行网站
  • 网站中英文切换怎么做个性化网站开发
  • 做外贸一般去什么网站找客户青岛市区商场黄页
  • 福建省建设相关网站wordpress建一个网站吗
  • 网站积分商城该怎么建立网站建设佛山
  • 大气微电影类网站织梦模板完整版阿里云域名 设置网站
  • 邯郸有设计网站的吗购物网站制作样例
  • 哈尔滨免费自助建站模板北京网站设计引流微信hyhyk1
  • 淘宝客做网站推广比较实用的h5网页建设网站
  • 电子商务网站建设期末试卷答案中英西班牙网站建设
  • 房山营销型网站制作开发如何查看网站的关键词
  • php音乐网站设计北京网站建设市场
  • 网站建设报价 福州石家庄网站优化多少钱
  • 手机网站推荐导航页阿里云建站费用
  • 个人网站建设的背景做网站前的准备什么
  • 品牌网站开发公司网站怎么做好 优帮云