今天开发安卓软件记账本,首先我们从阿里巴巴矢量库里找到所需要的图标,并且打包
我们在idea里创建一个Android项目,将图片各分到不同的文件夹里,然后再layout里创建几个主要的页面布局,具体效果如下
同时今天还编写了小键盘
然后通过一个java类来实现自定义小键盘的各项功能
package com.zhen.accountbook.utils; import android.inputmethodservice.Keyboard; import android.inputmethodservice.KeyboardView; import android.text.Editable; import android.text.InputType; import android.view.View; import android.widget.EditText; import com.zhen.accountbook.R; public class KeyBoardUtils { private final Keyboard k1; private KeyboardView keyboardView; private EditText editText; public interface OnEnsureListener { public void onEnsure(); } OnEnsureListener onEnsureListener; public void setOnEnsureListener(OnEnsureListener onEnsureListener) { this.onEnsureListener = onEnsureListener; } public KeyBoardUtils(KeyboardView keyboardView, EditText editText) { this.keyboardView = keyboardView; this.editText = editText; this.editText.setInputType(InputType.TYPE_NULL);//取消弹出系统键盘 k1 = new Keyboard(this.editText.getContext(), R.xml.key); this.keyboardView.setKeyboard(k1);//设置要显示键盘的样式 this.keyboardView.setEnabled(true); this.keyboardView.setPreviewEnabled(false); this.keyboardView.setOnKeyboardActionListener(listener);//设置键盘按钮被点击的监听 } KeyboardView.OnKeyboardActionListener listener = new KeyboardView.OnKeyboardActionListener() { @Override public void onPress(int i) { } @Override public void onRelease(int i) { } @Override public void onKey(int i, int[] ints) { Editable editable = editText.getText(); int start = editText.getSelectionStart(); switch (i) { case Keyboard.KEYCODE_DELETE: if (editable != null && editable.length() > 0) { if (start > 0) { editable.delete(start - 1, start); } } break;//点击了删除键 case Keyboard.KEYCODE_CANCEL: editable.clear(); break;//点击了清零 case Keyboard.KEYCODE_DONE: onEnsureListener.onEnsure();//通过接口回调的方法,当点击确定时,可以调用这个方法 break;//点击了完成 default://其他的数字直接插入 editable.insert(start, Character.toString((char) i)); break; } } @Override public void onText(CharSequence charSequence) { } @Override public void swipeLeft() { } @Override public void swipeRight() { } @Override public void swipeDown() { } @Override public void swipeUp() { } }; //显示键盘的方法 public void showKeyBoard() { int visibility = keyboardView.getVisibility(); if (visibility == View.INVISIBLE || visibility == View.GONE) { keyboardView.setVisibility(View.VISIBLE); } } //隐藏键盘的方法 public void hideKeyBoard() { int visibility = keyboardView.getVisibility(); if (visibility == View.INVISIBLE || visibility == View.VISIBLE) { keyboardView.setVisibility(View.GONE); } } }
今天就开发到这里,明天继续开发。
标签:editText,void,keyboardView,Override,import,2.20,public From: https://www.cnblogs.com/zzqq1314/p/18023133