Android 应用内自定义随机布局输入法,2024Android进阶新篇章

本文介绍了如何在Android应用中创建一个自定义的键盘视图(KeyboardView),包括设置布局、处理焦点事件和隐藏键盘。开发者展示了如何使用KeyboardBuilder类来管理键盘显示和EditText的关联。
摘要由CSDN通过智能技术生成

android:id=“@+id/keyboardview”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_alignParentBottom=“true”

android:layout_centerHorizontal=“true”

android:focusable=“true”

android:focusableInTouchMode=“true”

android:visibility=“gone” />

主界面代码

package com.demo.customime;

import android.app.Activity;

import android.inputmethodservice.KeyboardView;

import android.os.Bundle;

import android.view.WindowManager;

import android.widget.EditText;

public class MainActivity extends Activity {

private KeyboardBuilder builder;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

getWindow().setSoftInputMode(

WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

KeyboardView keyboardView = (KeyboardView) findViewById(R.id.keyboardview);

builder = new KeyboardBuilder(this, keyboardView, R.xml.keys_layout);

EditText editCustomIME = (EditText) findViewById(R.id.editCustomIME);

builder.registerEditText(editCustomIME);

}

@Override

public void onBackPressed() {

if (builder != null && builder.isCustomKeyboardVisible()) {

builder.hideCustomKeyboard();

} else {

this.finish();

}

}

}

键盘布局:

<?xml version="1.0" encoding="utf-8"?>

<Keyboard xmlns:android=“http://schemas.android.com/apk/res/android”

android:keyHeight=“10%p”

android:keyWidth=“25%p” >

<Key

android:codes=“55”

android:keyEdgeFlags=“left”

android:keyLabel=“7” />

<Key

android:codes=“56”

android:keyLabel=“8” />

<Key

android:codes=“57”

android:keyLabel=“9” />

<Key

android:codes=“60001”

android:isRepeatable=“true”

android:keyLabel=“DEL” />

<Key

android:codes=“52”

android:keyEdgeFlags=“left”

android:keyLabel=“4” />

<Key

android:codes=“53”

android:keyLabel=“5” />

<Key

android:codes=“54”

android:keyLabel=“6” />

<Key

android:codes=“48”

android:keyLabel=“0” />

<Key

android:codes=“49”

android:keyEdgeFlags=“left”

android:keyLabel=“1” />

<Key

android:codes=“50”

android:keyLabel=“2” />

<Key

android:codes=“51”

android:keyLabel=“3” />

<Key

android:codes=“60002”

android:keyLabel=“Cancel” />

常量

和输入法布局codes对应

package com.demo.customime;

public interface Constant {

int CodeDelete = 60001;

int CodeCancel = 60002;

}

KeyboardBuilder

package com.demo.customime;

import android.app.Activity;

import android.inputmethodservice.Keyboard;

import android.inputmethodservice.KeyboardView;

import android.text.Editable;

import android.text.InputType;

import android.util.Log;

import android.view.MotionEvent;

import android.view.View;

import android.view.inputmethod.InputMethodManager;

import android.widget.EditText;

public class KeyboardBuilder {

private static final String TAG = “KeyboardBuilder”;

private Activity mActivity;

private KeyboardView mKeyboardView;

public KeyboardBuilder(Activity ac, KeyboardView keyboardView,

int keyBoardXmlResId) {

mActivity = ac;

mKeyboardView = keyboardView;

Keyboard mKeyboard = new Keyboard(mActivity, keyBoardXmlResId);

// Attach the keyboard to the view

mKeyboardView.setKeyboard(mKeyboard);

// Do not show the preview balloons

mKeyboardView.setPreviewEnabled(false);

KeyboardView.OnKeyboardActionListener keyboardListener = new KeyboardView.OnKeyboardActionListener() {

@Override

public void onKey(int primaryCode, int[] keyCodes) {

// Get the EditText and its Editable

View focusCurrent = mActivity.getWindow().getCurrentFocus();

if (focusCurrent == null || !(focusCurrent instanceof EditText)) {

return;

}

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

总结

学习技术是一条慢长而艰苦的道路,不能靠一时激情,也不是熬几天几夜就能学好的,必须养成平时努力学习的习惯。所以:贵在坚持!

最后如何才能让我们在面试中对答如流呢?

答案当然是平时在工作或者学习中多提升自身实力的啦,那如何才能正确的学习,有方向的学习呢?有没有免费资料可以借鉴?为此我整理了一份Android学习资料路线:

这里是一部分我工作以来以及参与过的大大小小的面试收集总结出来的一套BAT大厂面试资料专题包,在这里免费分享给大家,主要还是希望大家在如今大环境不好的情况下面试能够顺利一点,希望可以帮助到大家。需要的小伙伴们可以点击我的GitHub获取免费领取方式

好了,今天的分享就到这里,如果你对在面试中遇到的问题,或者刚毕业及工作几年迷茫不知道该如何准备面试并突破现状提升自己,对于自己的未来还不够了解不知道给如何规划,可以去我的主页加一下技术群。来看看同行们都是如何突破现状,怎么学习的,来吸收他们的面试以及工作经验完善自己的之后的面试计划及职业规划。

最后,祝愿即将跳槽和已经开始求职的大家都能找到一份好的工作!

BAT大厂面试资料专题包,在这里免费分享给大家,主要还是希望大家在如今大环境不好的情况下面试能够顺利一点,希望可以帮助到大家。需要的小伙伴们可以点击我的GitHub获取免费领取方式

[外链图片转存中…(img-GQDvQk4Q-1711296837521)]

好了,今天的分享就到这里,如果你对在面试中遇到的问题,或者刚毕业及工作几年迷茫不知道该如何准备面试并突破现状提升自己,对于自己的未来还不够了解不知道给如何规划,可以去我的主页加一下技术群。来看看同行们都是如何突破现状,怎么学习的,来吸收他们的面试以及工作经验完善自己的之后的面试计划及职业规划。

最后,祝愿即将跳槽和已经开始求职的大家都能找到一份好的工作!

这些只是整理出来的部分面试题,后续会持续更新,希望通过这些高级面试题能够降低面试Android岗位的门槛,让更多的Android工程师理解Android系统,掌握Android系统。喜欢的话麻烦点击一个喜欢再关注一下~

  • 16
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值