鲨鱼记账App效果:

本文实现的效果图:

本文 不是什么原理分析,属于使用工具,不再具体分析。直接贴图贴代码了

自定义软键盘的XML模版

注:android:codes的值,请参考ASCII

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"android:horizontalGap="0px"android:keyWidth="33.333333%p"android:keyHeight="8.5%p"android:verticalGap="0px"><Row><Keyandroid:codes="49"android:keyLabel="1" /><Keyandroid:codes="50"android:keyLabel="2" /><Keyandroid:codes="51"android:keyLabel="3" /><Keyandroid:codes="-100000"android:keyLabel="今天" /></Row><Row><Keyandroid:codes="52"android:keyLabel="4" /><Keyandroid:codes="53"android:keyLabel="5" /><Keyandroid:codes="54"android:keyLabel="6" /><Keyandroid:codes="43"android:keyLabel="+" /></Row><Row><Keyandroid:codes="55"android:keyLabel="7" /><Keyandroid:codes="56"android:keyLabel="8" /><Keyandroid:codes="57"android:keyLabel="9" /><Keyandroid:codes="45"android:keyLabel="-" /></Row><Row><Keyandroid:codes="46"android:keyLabel="." /><Keyandroid:codes="48"android:keyLabel="0" /><Keyandroid:codes="-5"android:isRepeatable="true"android:keyIcon="@mipmap/joker_icon_delete" /><Keyandroid:codes="-4"android:keyLabel="完成" /></Row></Keyboard>

MainActivity的xml布局

注:etInput 这个EditText,在代码中设置的禁止获取焦点

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><TextViewandroid:layout_marginTop="30dp"android:id="@+id/tvKeyboradClick"android:layout_width="match_parent"android:layout_height="30dp"android:gravity="center"android:text="(仿鲨鱼记账)自定义软键盘"app:layout_constraintTop_toTopOf="parent" /><TextViewandroid:id="@+id/tvInputContent"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="30dp"android:gravity="center_horizontal"android:hint="输入内容"app:layout_constraintTop_toBottomOf="@id/tvKeyboradClick" /><LinearLayoutandroid:id="@+id/llKeborad"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:visibility="gone"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintHorizontal_weight="1"><FrameLayoutandroid:layout_width="match_parent"android:layout_height="40dp"><TextViewandroid:id="@+id/tvNoteHint"android:layout_width="wrap_content"android:layout_height="40dp"android:layout_marginLeft="5dp"android:drawableLeft="@mipmap/joker_icon_note"android:drawablePadding="10dp"android:gravity="center_vertical"android:minLines="1"android:singleLine="true"android:text="备注:"android:textColor="#222222"android:textSize="14dp" /><EditTextandroid:id="@+id/etNote"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_marginLeft="70dp"android:background="@null"android:gravity="left|center_vertical"android:hint="点击填写备注"android:maxLength="15"android:maxLines="1"android:singleLine="true"android:textColor="#222222"android:textColorHint="#989DB3"android:textSize="14dp" /><EditTextandroid:id="@+id/etInput"android:layout_width="wrap_content"android:layout_height="40dp"android:layout_gravity="right|center_vertical"android:layout_marginLeft="10dp"android:layout_marginRight="15dp"android:background="@null"android:drawablePadding="10dp"android:gravity="center_vertical"android:hint="0.00"android:maxLines="1"android:singleLine="true" /></FrameLayout><c.s.keyborad.JokerCustomKeyBoradViewandroid:id="@+id/keyboard_temp"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:background="@drawable/keyboard_background"android:focusable="true"android:focusableInTouchMode="true"android:keyBackground="@drawable/key_background"android:keyTextColor="#222222"android:paddingTop="0dp"android:paddingBottom="0dp"android:shadowRadius="0.0"android:visibility="visible" /></LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>

重写KeyboardView

注:这个根据自己的需要,如果需要对软键盘进行特殊绘制,就必须重写KeyboardView了。
主要工作:

  1. 键盘的绘制
public class JokerCustomKeyBoradView extends KeyboardView {private Context context;private Paint paint;private Rect bounds;public JokerCustomKeyBoradView(Context context, AttributeSet attrs) {super(context, attrs);paint = new Paint();paint.setTextAlign(Paint.Align.CENTER);paint.setAntiAlias(true);paint.setColor(Color.BLACK);bounds = new Rect();this.context = context;}public JokerCustomKeyBoradView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);paint = new Paint();paint.setTextAlign(Paint.Align.CENTER);paint.setAntiAlias(true);paint.setColor(Color.BLACK);bounds = new Rect();this.context = context;}Canvas canvas;@Overridepublic void onDraw(Canvas canvas) {super.onDraw(canvas);this.canvas = canvas;List<Keyboard.Key> keys = getKeyboard().getKeys();for (Keyboard.Key key : keys) {if (key.codes[0] == -4) { // = 和 完成drawSpecialKey(canvas, key);} else if (key.codes[0] == -5) {//删除} else {//绘制普通信息文本的背景drawBackground(R.drawable.key_background, canvas, key);}//绘制普通信息的文本信息drawText(canvas, key);}}private void drawSpecialKey(Canvas canvas, Keyboard.Key key) {if (key.codes[0] == -4) {drawBackground(R.drawable.key_done_background, canvas, key);}// 可根据code值,进行区分绘制}private void drawBackground(@DrawableRes int drawableId, Canvas canvas, Keyboard.Key key) {Drawable drawable = context.getResources().getDrawable(drawableId);int[] state = key.getCurrentDrawableState();if (key.codes[0] != 0) {drawable.setState(state);}drawable.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);drawable.draw(canvas);}public void drawText(Canvas canvas, Keyboard.Key key) {if (key.label != null) {String label = key.label.toString();Field field;int keyTextSize;try {//获取KeyboardView设置的默认文本字体大小field = KeyboardView.class.getDeclaredField("mLabelTextSize");field.setAccessible(true);keyTextSize = (int) field.get(this);paint.setTextSize(keyTextSize);if (key.codes[0] == -4) {paint.setColor(Color.parseColor("#FFFFFF"));} else {paint.setColor(Color.parseColor("#222222"));}paint.setTypeface(Typeface.DEFAULT);paint.getTextBounds(label, 0, label.length(), bounds);canvas.drawText(label, key.x + (key.width / 2), (key.y + key.height / 2) + bounds.height() / 2, paint);} catch (NoSuchFieldException | IllegalAccessException e) {e.printStackTrace();}}}
}

编写帮助类JokerKeyBoradHelper

主要工作:

  1. 键盘的输入监听
  2. 加减法的计算

具体的逻辑注释已经写的很详细。

public class JokerKeyBoradHelper {private Context context;private JokerCustomKeyBoradView keyboardView;private EditText editText; //显示该键盘的EditTextprivate Keyboard k1;// 自定义键盘private KeyboardCallBack callBack;//按键回调监听public JokerKeyBoradHelper(Context context, JokerCustomKeyBoradView keyboardView) {this(context, keyboardView, null);}public JokerKeyBoradHelper(Context context, JokerCustomKeyBoradView keyboardView, KeyboardCallBack callBack) {this.context = context;k1 = new Keyboard(context, R.xml.joker_keyboard_temp);//据Keyboard的xml布局绑定this.keyboardView = keyboardView;this.keyboardView.setOnKeyboardActionListener(listener);//设置键盘监听this.keyboardView.setKeyboard(k1);//设置默认键盘this.keyboardView.setEnabled(true);this.keyboardView.setPreviewEnabled(false);this.callBack = callBack;}public JokerCustomKeyBoradView getKeyBoradView() {return keyboardView;}/**
*根据code,返回一个具体的key对象
*/public Keyboard.Key getKey(int code) {Keyboard.Key key = null;if (k1 != null) {for (int i = 0; i < k1.getKeys().size(); i++) {int[] codes = k1.getKeys().get(i).codes;if (codes[0] == code) {key = k1.getKeys().get(i);break;}}}return key;}private KeyboardView.OnKeyboardActionListener listener = new KeyboardView.OnKeyboardActionListener() {@Overridepublic void swipeUp() {}@Overridepublic void swipeRight() {}@Overridepublic void swipeLeft() {}@Overridepublic void swipeDown() {}@Overridepublic void onText(CharSequence text) {//当key中有keyOutputText属性时,点击键盘会触发该方法,回调keyOutputText的值Editable editable = (Editable) editText.getText();int end = editText.getSelectionEnd();editable.delete(0, end);editable.insert(0, text);}@Overridepublic void onRelease(int primaryCode) {}@Overridepublic void onPress(int primaryCode) {}@Overridepublic void onKey(int primaryCode, int[] keyCodes) {//设置了codes属性后,点击键盘会触发该方法,回调codes的值//codes值与ASCLL码对应Editable editable = editText.getText();int start = editText.getSelectionStart();int end = editText.getSelectionEnd();switch (primaryCode) {case Keyboard.KEYCODE_DELETE:if (editable != null && editable.length() > 0) {if (start == end) {editable.delete(start - 1, start);} else {editable.delete(start, end);}}break;case Keyboard.KEYCODE_DONE:if (callBack != null) {// =:计算。完成:回调Keyboard.Key key = getKey(-4);if (key.label.equals("=")) {if (start != end) {editable.delete(start, end);}if (defaultLogic((char) primaryCode, editable, start, end, true))return;} else {callBack.doneCallback();}}break;case -100000:if (callBack != null) {callBack.dateCallback(getKey(-100000));}break;default:if (start != end) {editable.delete(start, end);}if (defaultLogic((char) primaryCode, editable, start, end, false)) return;break;}if (callBack != null) {callBack.keyCall(primaryCode, editText.getText().toString());}}};/*** @param isequals 用户是不是点击的=号*                 注意:isequals=true时,不能判断以 primaryCode 为判断标准。*                 因为 =号/完成:这个是取的系统的状态code(完成:code=-4),转成char是个空值*/private boolean defaultLogic(char primaryCode, Editable editable, int start, int end, boolean isequals) {Log.i("Joker", "KeyBoradHelper: primaryCode = " + primaryCode);/*** 只要输入+ 或 -  更改=状态* */if (Character.toString(primaryCode).equals("+") || Character.toString(primaryCode).equals("-")) {Keyboard.Key key = getKey(-4);key.label = "=";}/***editText当前的值为0,后面不能继续输入0。即:开头为:00 情况  为0时,继续输入数字时直接把0替换掉* */if (editText.getText().toString().equals("0") && (Character.toString(primaryCode).equals("0")|| Character.toString(primaryCode).equals("0")|| Character.toString(primaryCode).equals("1")|| Character.toString(primaryCode).equals("2")|| Character.toString(primaryCode).equals("3")|| Character.toString(primaryCode).equals("4")|| Character.toString(primaryCode).equals("5")|| Character.toString(primaryCode).equals("6")|| Character.toString(primaryCode).equals("7")|| Character.toString(primaryCode).equals("8")|| Character.toString(primaryCode).equals("9"))) {editable.delete(0, end);editable.insert(0, Character.toString(primaryCode));start = editText.getSelectionStart();return true;}/** =* 不能以 . +  -* */if (editText.getText().toString().isEmpty()) {if (Character.toString(primaryCode).equals(".") || Character.toString(primaryCode).equals("+") || Character.toString(primaryCode).equals("-")) {return true;}}/***  避免连续输入 . +  -* */if (editText.getText().toString().endsWith("+") || editText.getText().toString().endsWith("-") || editText.getText().toString().endsWith(".")) {// 避免重复连续的+ 或 -号if (Character.toString(primaryCode).toString().equals("+") || Character.toString(primaryCode).toString().equals("-") || Character.toString(primaryCode).toString().equals(".") || isequals) {// 以+、-、结尾时 用户点击 = 计算    以 . 结尾时不能去计算if (isequals && !editText.getText().toString().endsWith(".")) {String input = editText.getText().toString();String substring = input.substring(0, input.length() - 1);editable.delete(0, end);// 删除已经插入editable.insert(0, substring);//把插入计算结果Keyboard.Key key = getKey(-4);if (key != null) { //  以+ - 结尾时的计算后,需要把 = 号恢复为完成状态key.label = "完成";}return true;}Log.i("JokerKeyBoradHelper", ". +  - 再次结尾输入不处理");} else {Log.i("JokerKeyBoradHelper", "插入");editable.insert(start, Character.toString(primaryCode));}} else {// editText中已经存在+ 或 -  再继续输入就进行计算if (editText.getText().toString().contains("+") || editText.getText().toString().contains("-")) {/*** 1、输入的是+ 或 - 计算* 2、如果是按的=  计算(不把=号 插入结果后面) isequals是判断是不是点击的=*/if (Character.toString(primaryCode).equals("+") || Character.toString(primaryCode).equals("-") || isequals) {if (editText.getText().toString().contains("+")) {/*** 加法计算* 1.editText存在 +  在输入 +或- 就会自动进行计算* 2.负数场景:计算过一次,得到负数,继续输入进行计算* */String[] split = editText.getText().toString().replace("+", ",").split(",");if (split == null) return true;if (split.length > 1) {String addResult = toCalculate(split, true);editable.delete(0, end);// 删除已经插入的editable.insert(0, addResult);//重新插入计算结果if (!isequals) {start = editText.getSelectionStart(); // 重新获取插入开始位置editable.insert(start, Character.toString(primaryCode));// 把加号在插入到后面}} else {Log.i("Joker", "KeyBoradHelper: editText = " + editText.getText().toString() + "\n Split length = " + split.length);}} else if (editText.getText().toString().contains("-")) { //&& Character.toString((char) primaryCode).equals("-")/*** 减法计算:3种场景*   1.需要判断第一次计算产生负数(- 开头),继续进行 - 或 = 输入计算。*   2.需要判断第一次计算产生负数(- 开头),继续输入- 计算,在点击 = ,在输入 - 计算的情况。 例如:上次计算结果为负数为-3。-3-3,继续输入-,Edittext得到:-6-,按= 得到-6,在按- 计算的情况*   3.editText存在- (两个整数相减) 继续输入  + 或 - 就会自动进行计算* */String[] split = null;if (editText.getText().toString().startsWith("-")) { // -号开头int indexOf = editText.getText().toString().lastIndexOf("-");if (indexOf != 0) {StringBuilder builder = new StringBuilder(editText.getText().toString());builder.replace(indexOf, indexOf + 1, ","); // 替换指定位置的字符split = builder.toString().split(",");Log.i("Joker", "-开头:indexOf!=0  ->indexof = " + indexOf + "\nbuilder = " + builder.toString() + "\n split = " + split.length + "  split[0]= " + split[0] + "  split[1]= " + split[1]);} else {editable.insert(start, Character.toString(primaryCode));Log.i("Joker", "-开头:indexof = " + indexOf);}} else {split = editText.getText().toString().replace("-", ",").split(",");}if (split == null) return true;if (split.length > 1) {String addResult = toCalculate(split, false);editable.delete(0, end);// 删除已经插入editable.insert(0, addResult);//把插入计算结果if (!isequals) {// 按的 =  不插入结果后面start = editText.getSelectionStart(); // 重新获取插入开始位置editable.insert(start, Character.toString(primaryCode));// 把加号在插入到后面}} else {Log.i("JokerKeyBoradHelper - ", editText.getText().toString() + " Split length = " + split.length);}}} else {editable.insert(start, Character.toString(primaryCode));}} else {editable.insert(start, Character.toString(primaryCode));}}return false;}//计算public String toCalculate(String[] split, boolean isAddition) {String add_1 = split[0].isEmpty() ? "0" : split[0];String add_2 = split[1];String addResult = "";int i_1 = 0;int i_2 = 0;double d_1 = 0;double d_2 = 0;/*** 1、判断是否是小数* */Log.i("toCalculate ", add_1 + "__" + add_2);if (add_1.contains(".")) {d_1 = Double.parseDouble(add_1);} else {i_1 = Integer.parseInt(add_1);}if (add_2.contains(".")) {d_2 = Double.parseDouble(add_2);} else {i_2 = Integer.parseInt(add_2);}if (isAddition) {if ((i_1 == 0 && d_1 != 0) && (i_2 == 0 && d_2 != 0)) {//d_1 + d_2addResult = (d_1 + d_2) + "";}if ((i_1 != 0 && d_1 == 0) && (i_2 == 0 && d_2 != 0)) {//i_1 + d_2addResult = (i_1 + d_2) + "";}if ((i_1 != 0 && d_1 == 0) && (i_2 != 0 && d_2 == 0)) {//i_1 + i_2addResult = (i_1 + i_2) + "";}if ((i_1 == 0 && d_1 != 0) && (i_2 != 0 && d_2 == 0)) {//d_1 + i_2addResult = (d_1 + i_2) + "";}// 0开头情况if ((i_1 == 0 && d_1 == 0) && (i_2 != 0 && d_2 == 0)) {//addResult = (0 + i_2) + "";}if ((i_1 == 0 && d_1 == 0) && (i_2 == 0 && d_2 != 0)) {//addResult = (0 + d_2) + "";}if ((i_1 != 0 && d_1 == 0) && (i_2 == 0 && d_2 == 0)) {//addResult = (i_1 + 0) + "";}if ((i_1 == 0 && d_1 != 0) && (i_2 == 0 && d_2 == 0)) {//addResult = (d_1 + 0) + "";}} else {if ((i_1 == 0 && d_1 != 0) && (i_2 == 0 && d_2 != 0)) {//d_1 + d_2addResult = (d_1 - d_2) + "";}if ((i_1 != 0 && d_1 == 0) && (i_2 == 0 && d_2 != 0)) {//i_1 + d_2addResult = (i_1 - d_2) + "";}if ((i_1 != 0 && d_1 == 0) && (i_2 != 0 && d_2 == 0)) {//i_1 + i_2addResult = (i_1 - i_2) + "";}if ((i_1 == 0 && d_1 != 0) && (i_2 != 0 && d_2 == 0)) {//d_1 + i_2addResult = (d_1 - i_2) + "";}// 0 开头if ((i_1 == 0 && d_1 == 0) && ((i_2 == 0 && d_2 != 0))) {addResult = (0 - d_2) + "";}if ((i_1 == 0 && d_1 == 0) && ((i_2 != 0 && d_2 == 0))) {addResult = (0 - i_2) + "";}if ((i_1 != 0 && d_1 == 0) && ((i_2 == 0 && d_2 == 0))) {addResult = (i_1 - 0) + "";}if ((i_1 == 0 && d_1 != 0) && ((i_2 == 0 && d_2 == 0))) {addResult = (d_1 - 0) + "";}}return addResult;}//在显示键盘前应调用此方法,指定EditText与KeyboardView绑定public void setEditText(EditText editText) {this.editText = editText;//关闭进入该界面获取焦点后弹出的系统键盘InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);if (imm != null) {imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);}//隐藏该EditText获取焦点而要弹出的系统键盘JokerKeyboardUtil.hideSoftInput(editText);}//Activity中获取焦点时调用,显示出键盘public void show() {int visibility = keyboardView.getVisibility();if (visibility == View.GONE || visibility == View.INVISIBLE) {keyboardView.setVisibility(View.VISIBLE);}}//隐藏键盘public void hide() {int visibility = keyboardView.getVisibility();if (visibility == View.VISIBLE) {keyboardView.setVisibility(View.GONE);}}public boolean isVisibility() {if (keyboardView.getVisibility() == View.VISIBLE) {return true;} else {return false;}}public interface KeyboardCallBack {void keyCall(int code, String content);void doneCallback();void dateCallback(Keyboard.Key key);}//设置回调,用于自定义特殊按键在不同界面或EditText的处理public void setCallBack(KeyboardCallBack callBack) {this.callBack = callBack;}
}

具体使用

public class MainActivity extends AppCompatActivity {EditText etInput, etNote;LinearLayout llKeborad;TextView tvInputContent, tvKeyboradClick;JokerCustomKeyBoradView keyboard_temp;JokerKeyBoradHelper helper;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tvKeyboradClick = findViewById(R.id.tvKeyboradClick);tvInputContent = findViewById(R.id.tvInputContent);etNote = findViewById(R.id.etNote);etInput = findViewById(R.id.etInput);keyboard_temp = findViewById(R.id.keyboard_temp);llKeborad = findViewById(R.id.llKeborad);initKey();tvKeyboradClick.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {if (llKeborad.getVisibility() == View.GONE) {llKeborad.setVisibility(View.VISIBLE);}}});}private void initKey() {// 设置禁止获取焦点,这个etInput用于键盘输入和计算结果的展示etInput.setFocusable(false);etInput.setFocusableInTouchMode(false);//初始化KeyboardViewhelper = new JokerKeyBoradHelper(this, keyboard_temp);// 软键盘捆绑etInputhelper.setEditText(etInput);helper.setCallBack(new JokerKeyBoradHelper.KeyboardCallBack() {@Overridepublic void keyCall(int code, String content) {//                if (!content.isEmpty() && !content.startsWith("+") && !content.startsWith("-")) {//                    if (content.contains("+") || content.contains("-")) {//                        //回调键盘监听,根据回调的code值进行处理
//                        if (code == 43 || code == 45) {//                            Keyboard.Key key = helper.getKey(-4);
//                            key.label = "=";
//                        }
//                    } else {//                        Keyboard.Key key = helper.getKey(-4);
//                        key.label = "完成";
//                    }
//                }if (!content.isEmpty()){if (code == 43 || code == 45) {Keyboard.Key key = helper.getKey(-4);key.label = "=";Log.i("=coed ",code+"  "+ key.label );}if (code ==-4) {Keyboard.Key key = helper.getKey(-4);key.label = "完成";Log.i("=--coed ",code+"   "+ key.label );}}}@Overridepublic void doneCallback() {String etnote = etNote.getText().toString().trim();String tvinput = etInput.getText().toString().trim();Keyboard.Key key = helper.getKey(-100000);tvInputContent.setText("备注:" + etnote + "\n计算结果 = " + tvinput + "\n时间 = " + key.label);}@Overridepublic void dateCallback(final Keyboard.Key key) {DateSelectDialog.getCalendar(MainActivity.this, new DateSelectDialog.DateTimeCallback() {@Overridepublic Void timeCallback(String time) {key.label = time;// 这里调用了系统日历,需要调用view的postInvalidate进行重绘helper.getKeyBoradView().postInvalidate();return null;}});}});}
}

JokerKeyboardUtil


public class JokerKeyboardUtil {//隐藏系统键盘//安卓4.0以下隐藏软键盘只需setInputType(InputType.TYPE_NULL)即可//4.0及以上,4.2以下需要调用setSoftInputShownOnFocus方法//4.2以上需要调用setShowSoftInputOnFocus方法//由于sdk的不一致,此处使用反射进行处理public static void hideSoftInput(EditText ed) {int currentVersion = android.os.Build.VERSION.SDK_INT;String methodName = null;if (currentVersion >= 16) {// 4.2methodName = "setShowSoftInputOnFocus";} else if (currentVersion >= 14) {// 4.0methodName = "setSoftInputShownOnFocus";}if (methodName == null) {ed.setInputType(InputType.TYPE_NULL);} else {Class<EditText> cls = EditText.class;Method setShowSoftInputOnFocus;try {setShowSoftInputOnFocus = cls.getMethod(methodName, boolean.class);setShowSoftInputOnFocus.setAccessible(true);setShowSoftInputOnFocus.invoke(ed, false);} catch (Exception e) {ed.setInputType(InputType.TYPE_NULL);e.printStackTrace();}}}//显示被隐藏的系统键盘public static void showSoftInput(EditText ed) {InputMethodManager inputManager = (InputMethodManager) ed.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);inputManager.showSoftInput(ed, 0);}
}

其他用到的资源/类

  1. key_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:bottom="0.5dp"android:left="0.5dp"android:right="0.5dp"android:top="0.5dp"><selector><item android:state_pressed="true"><shape><solid android:color="#ffffff" /><corners android:radius="0dp" /></shape></item><item><shape><solid android:color="#ffffff" /><corners android:radius="0dp" /></shape></item></selector></item>
</layer-list>
  1. key_done_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:bottom="0dp"android:left="0dp"android:right="0dp"android:top="0dp"><shape><solid android:color="#2C54F5" /><corners android:radius="0dp" /></shape></item>
</layer-list>
  1. keyboard_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><solid android:color="#cacaca" /><corners android:radius="0dp"/><strokeandroid:width="0.5dp"android:color="#E9EBF5" />
</shape>

遗留问题

  1. 对于输入的小数,没有做位数的限制
  2. 对于 数字+0 这样格式,可以继续输入0,如:2+001这样。不过不影响计算结果

看官有需要,可自行扩展。

Android自定义记账软键盘(仿鲨鱼记账的记账功能)相关推荐

  1. Android 自定义安全软键盘 SafeKeyboard 开发详细说明 2.0

    Android 自定义安全软键盘 SafeKeyboard 开发详细说明 2.0 源码地址:GitHub:    https://github.com/SValence/SafeKeyboard 注意 ...

  2. android 自定义数字软键盘,Android自定义键盘的实现(数字键盘和字母键盘)

    在项目中,产品对于输入方式会有特殊的要求,需要对输入方式增加特定的限制,这就需要采用自定义键盘.本文主要讲述数字键盘和字母键盘的自定义实现. 自定义键盘的实现步骤如下: 自定义CustomKeyboa ...

  3. Android自定义输入法软键盘

    1 功能描述 触屏设备主界面中有一个文本编辑框,底部区域固定显示一个数字键盘,键盘中除数字键外,还带有*和#键功能: 提供一个自定义的数字输入法,生成apk安装包文件,嵌入到img镜像文件中去. 2 ...

  4. android 键盘将底部视图顶起,android 弹出软键盘将底部视图顶起问题

    今天要做一个搜索功能,搜索界面采用AutoCompleteTextView做搜索条,然后下面用listview来显示搜索结果,而我的主界面是在底 部用tab做了一个主界面导航,其中有一个搜索按钮,因为 ...

  5. Android 监听软键盘的高度并解决其覆盖输入框的问题

    1.前言 在某些项目中,我们常常需要自定义一个输入框,软键盘弹出时就把输入框顶上去,关闭时输入框再回到原位(比如下方的效果图,实际上各种 App 中的聊天界面和发布评论的界面大体都是这样).在这个过程 ...

  6. Android PopupWindow 隐藏软键盘的方法

    今天,简单讲讲android里  PopupWindow 弹出在底部,被软键盘遮挡的问题. 之前,自己写一个PopupWindow 弹出在底部,可是如果软键盘显示时弹出,软键盘会遮挡PopupWi ...

  7. Android 文本,软键盘使用指南

    目录 TextView的基本使用 TextView的基本属性 图文混排的三种实现方式 drawableTop,DrawableBottom,DrawableLeft,drawableRight 通过I ...

  8. Android EditText将软键盘的回车改为搜索,并监听

    需求为: 当用户在界面内点击输入框,弹出键盘,键盘右下角示意为"搜索"按钮 当用户输入内容后,点击搜索按钮将进行关键词搜索 当用户没有输入内容点击搜索按钮,将收起键盘,回到界面(这 ...

  9. android动态设置软键盘弹出模式,Android 弹出软键盘所遇到的坑及解决方法

    重要代码: //1.此layout作为最外层的layout: //2.设置需要调整的view: setAdjustView(View view); //3.如果需要控制输入框的显示与隐藏,可以实现On ...

最新文章

  1. SQL -- 多表查询
  2. js find的用法_React常用库Immutable.js常用API
  3. eclipse+tomcat开发web程序
  4. JavaScript+ Canvas开发趣味小游戏《贪吃蛇》
  5. python程序员工作时间_黑马程序员:Python编程之时间和日期模块
  6. 12_电话拨号器_界面实现
  7. cmd后台运行exe_了解运行命令的原理,为QQ制作运行命令启动
  8. 从stm32转向Linux,STM32MP1Distrib
  9. 让Cocos2dx中的TestCPP中的Box2dTest运行起来
  10. 【机器学习笔记】有监督学习和无监督学习
  11. 计算机主机号截图,电脑如何截图?截图三种方法推荐
  12. 背景图片虚化的效果的css样式的实现
  13. 关于编写性能高效的javascript事件的技术[转] 来源:酷勤网 发布于 2015-2-12
  14. 使用计算机有关的活动,有关计算机的活动策划书
  15. 博弈论读书笔记(二):纳什均衡与野猪博弈
  16. 使用TEXT函数处理日期时间
  17. beego框架:static目录下的apk文件浏览器下载使用正常,手机浏览器下载无法解析安装
  18. 中国颅骨固定系统行业市场供需与战略研究报告
  19. 支付宝支付 62009
  20. 数据结构实验6图的应用-行车路线问题

热门文章

  1. 为什么很多企业都在使用短信群发?原来是有3大好处!
  2. 安装groovy时安照说明配置环境变量
  3. 集成产品开发(IPD)简介
  4. PTA作业记录2(计算油费)
  5. go get connectex: A connection attempt failed because the connected party did not properly respond
  6. ESP8266 RTOS SDK学习之 UDP
  7. 多媒体计算机系统有何特征,多媒体的特点主要包括哪些?
  8. Spring Cloud Netfilx Zuul : API网关服务
  9. 软件测试学习 之 Python 函数默认参数
  10. raid是什么?raid的工作原理分析及raid数据恢复思路