最后
写到这里也结束了,在文章最后放上一个小小的福利,以下为小编自己在学习过程中整理出的一个学习思路及方向,从事互联网开发,最主要的是要学好技术,而学习技术是一条慢长而艰苦的道路,不能靠一时激情,也不是熬几天几夜就能学好的,必须养成平时努力学习的习惯,更加需要准确的学习方向达到有效的学习效果。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
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;
}
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();
}
总结
作为一名从事Android的开发者,很多人最近都在和我吐槽Android是不是快要凉了?而在我看来这正是市场成熟的表现,所有的市场都是温水煮青蛙,永远会淘汰掉不愿意学习改变,安于现状的那批人,希望所有的人能在大浪淘沙中留下来,因为对于市场的逐渐成熟,平凡并不是我们唯一的答案!
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
和我吐槽Android是不是快要凉了?而在我看来这正是市场成熟的表现,所有的市场都是温水煮青蛙,永远会淘汰掉不愿意学习改变,安于现状的那批人,希望所有的人能在大浪淘沙中留下来,因为对于市场的逐渐成熟,平凡并不是我们唯一的答案!
[外链图片转存中…(img-KFrzx2v0-1715650242484)]
[外链图片转存中…(img-U22SqBss-1715650242485)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!