Android 应用内自定义随机布局输入法,如何试出一个Android开发者真正的水平

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.EditTex

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整资料开源分享

t;

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;

}

EditText edittext = (EditText) focusCurrent;

Editable editable = edittext.getText();

int start = edittext.getSelectionStart();

// Handle key

if (primaryCode == Constant.CodeCancel) {

hideCustomKeyboard();

} else if (primaryCode == Constant.CodeDelete) {

if (editable != null && start > 0) {

editable.delete(start - 1, start);

}

} else {

// Insert character

editable.insert(start,

Character.toString((char) primaryCode));

}

}

@Override

public void onPress(int arg0) {

}

@Override

public void onRelease(int primaryCode) {

}

@Override

public void onText(CharSequence text) {

}

@Override

public void swipeDown() {

}

@Override

public void swipeLeft() {

}

@Override

public void swipeRight() {

}

@Override

public void swipeUp() {

}

};

mKeyboardView.setOnKeyboardActionListener(keyboardListener);

}

// 绑定一个EditText

public void registerEditText(EditText editText) {

// Make the custom keyboard appear

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

@Override

public void onFocusChange(View v, boolean hasFocus) {

if (hasFocus) {

showCustomKeyboard(v);

} else {

hideCustomKeyboard();

}

}

});

editText.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Log.d(TAG, “onClick”);

showCustomKeyboard(v);

}

});

editText.setOnTouchListener(new View.OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

Log.d(TAG, “onTouch”);

EditText edittext = (EditText) v;

int inType = edittext.getInputType(); // Backup the input type

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值