Android开发仿咸鱼键盘DEMO(修改版)

Android开发仿咸鱼键盘DEMO(修改版),第1张

概述在这里布局我就不贴出来了/***最终被调用的修改价格dialog*/protectedvoideditPriceDialog(){

在这里布局我就不贴出来了

/** * 最终被调用的修改价格dialog */ protected voID editPriceDialog() { // Todo auto-generated method stub editPriceVIEw = VIEw.inflate(this,R.layout.dialog_price_input_keyboard,null); priceDialog = new Dialog(this,R.style.contactdialog); priceDialog.requestwindowFeature(Window.FEATURE_NO_Title); Window PriceDialogwindow = priceDialog.getwindow(); PriceDialogwindow.setGravity(Gravity.BottOM); priceDialog.setContentVIEw(editPriceVIEw); priceDialog.getwindow().getAttributes().windowAnimations = R.style.DialogAnimation; priceDialog.show(); tv_softkb_point = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_point); buffer = new StringBuffer(); stringbuffer = buffer.toString(); buffer2 = new StringBuffer(); stringbuffer2 = buffer2.toString(); etGoodsPrice = (EditText) editPriceVIEw.findVIEwByID(R.ID.et_goodsPrice); etGoodsPrice.addTextChangedListener(new TextWatcher() { private String etPricetrim; @OverrIDe public voID onTextChanged(CharSequence s,int start,int before,int count) { etPricetrim = s.toString().trim(); if (etPricetrim.length() == 1 && s.toString().equals(".")) { //如果edittext的长度为1并且用户只输入了一个.那么buffer里追加"0" + "." 同时删除我们输入的点 //如果不删除的在则 buffer里的数据会是 .0. buffer.append("0").append(".").deleteCharat(0); etGoodsPrice.setText(buffer.toString()); } if (s.toString().contains(".")) { //如果s里包含点 if (s.length() - 1 - s.toString().indexOf(".") > 2) { if(tv_softkb_point!=null){ tv_softkb_point.setClickable(false); } if(buffer!=null&&buffer.length()>=1){ buffer.deleteCharat(buffer.length()-1); } s = s.toString().subSequence(0,s.toString().indexOf(".") + 3); etGoodsPrice.setText(s); etGoodsPrice.setSelection(s.length()); } else if(s.length()-1-s.toString().indexOf(".")<=2){ if(tv_softkb_point!=null){ tv_softkb_point.setClickable(false); } } } else { if(tv_softkb_point!=null) { tv_softkb_point.setClickable(true); tv_softkb_point.setEnabled(true); } } if (s.toString().startsWith("0") && s.toString().trim().length() > 1) { //如果以0开头长度大于1 第二个元素不是. if (!s.toString().substring(1,2).equals(".")) { buffer.deleteCharat(1); etGoodsPrice.setText(s.subSequence(0,1)); etGoodsPrice.setSelection(1); return; } } } @OverrIDe public voID beforeTextChanged(CharSequence s,int count,int after) { } @OverrIDe public voID afterTextChanged(Editable s) { int length = etPricetrim.length(); if (length >=1) { etGoodsPrice.setSelection(length); } else { etGoodsPrice.setSelection(0); } // Toast.makeText(PostIssueActivity.this,s.toString(),0).show(); if(s.toString()!=null&&s.toString().contains(".")){ //通过s取出当前editext上的传 来判断是否包含. 如果包含的话则把 clickbale设置成false同时置为不可点击 if(tv_softkb_point!=null) { tv_softkb_point.setClickable(false); tv_softkb_point.setEnabled(false); } } // if(s.toString().length()==1&&s.toString().equals("0")) { //如果长度是1 并且是以0开头 这个时候光标是定位在0后 则删除buffer // //里的第一个char 并设置 // //// buffer.deleteCharat(0); //// etGoodsPrice.setText(buffer.toString()); // // } } }); if (!iPriceEdit.getText().toString().substring(1,iPriceEdit.getText().length()).toString().equals("0.00")) { etGoodsPrice .setText(iPriceEdit.getText().toString().substring(1,iPriceEdit.getText().length()).toString()); etGoodsPrice.setSelection(etGoodsPrice.length()); buffer.append(iPriceEdit.getText().toString().substring(1,iPriceEdit.getText().length()).toString()); } else { etGoodsPrice.setText(""); etGoodsPrice.setHint("0.00"); buffer.append(""); } etoriginalPrice = (EditText) editPriceVIEw.findVIEwByID(R.ID.et_originalPrice); etoriginalPrice.addTextChangedListener(new TextWatcher() { private String trim; @OverrIDe public voID onTextChanged(CharSequence s,int count) { trim = s.toString().trim(); if (etoriginalPrice.length() == 1 && s.toString().equals(".")) { buffer2.append("0").append(".").deleteCharat(0); etoriginalPrice.setText(buffer2.toString()); } if (s.toString().contains(".")) { if (s.length() - 1 - s.toString().indexOf(".") > 2) { if(tv_softkb_point!=null){ tv_softkb_point.setClickable(false); } if(buffer2!=null&&buffer2.length()>=1){ buffer2.deleteCharat(buffer2.length()-1); } s = s.toString().subSequence(0,s.toString().indexOf(".") + 3); etoriginalPrice.setText(s); etoriginalPrice.setSelection(s.length()); } else if(s.length()-1-s.toString().indexOf(".")<=2){ if(tv_softkb_point!=null){ tv_softkb_point.setClickable(false); } } } else { if(tv_softkb_point!=null) { tv_softkb_point.setClickable(true); tv_softkb_point.setEnabled(true); } } if (s.toString().startsWith("0") && s.toString().trim().length() > 1) { if (!s.toString().substring(1,2).equals(".")) { buffer2.deleteCharat(1); etoriginalPrice.setText(s.subSequence(0,1)); etoriginalPrice.setSelection(1); return; } } } @OverrIDe public voID beforeTextChanged(CharSequence s,int after) { // Todo auto-generated method stub } @OverrIDe public voID afterTextChanged(Editable s) { // Todo auto-generated method stub int length = trim.length(); if (length >=1) { etoriginalPrice.setSelection(length); } else { etoriginalPrice.setSelection(0); } if(s.toString()!=null&&s.toString().contains(".")){ if(tv_softkb_point!=null) { tv_softkb_point.setClickable(false); tv_softkb_point.setEnabled(false); } } // if(s.toString().length()==1&&s.toString().equals("0")) { //如果长度是1 并且是以0开头 这个时候光标是定位在0后 则删除buffer // //里的第一个char 并设置 // // buffer2.deleteCharat(0); // etoriginalPrice.setText(buffer2.toString()); // // } } }); etoriginalPrice.setSelection(etoriginalPrice.length()); if (!ioldPriceEdit.getText().subSequence(1,ioldPriceEdit.getText().length()).toString().equals("0.00")) { etoriginalPrice .setText(ioldPriceEdit.getText().subSequence(1,ioldPriceEdit.getText().length()).toString()); buffer2.append(ioldPriceEdit.getText().subSequence(1,ioldPriceEdit.getText().length()).toString()); } else { etoriginalPrice.setText(""); etoriginalPrice.setHint("0.00"); buffer2.append(""); } // etoriginalPrice.requestFocus(); // etoriginalPrice.setSelection(etGoodsPrice.getText().length()); ImageVIEw tv_softkb_hIDdenkb = (ImageVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_hIDdenkb); ImageVIEw ivDelete = (ImageVIEw) editPriceVIEw.findVIEwByID(R.ID.iv_delete); ivDelete.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Toast.makeText(PostIssueActivity.this,"dddd",0).show(); delNumber(); } }); // 长按删除键 事件 ivDelete.setonLongClickListener(new OnLongClickListener() { @OverrIDe public boolean onLongClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.delete(0,etGoodsPrice.getText().length()); // if(etGoodsPrice.getText().length()>=1){ // buffer.deleteCharat(etGoodsPrice.getText().length()-1); // } stringbuffer = buffer.toString(); etGoodsPrice.setText(stringbuffer.substring(0,stringbuffer.length())); } if (etoriginalPrice.hasFocus()) { buffer2.delete(0,etoriginalPrice.getText().length()); // if(etoriginalPrice.getText().length()>=1){ // buffer2.deleteCharat(etoriginalPrice.getText().length()-1); // } stringbuffer2 = buffer2.toString(); etoriginalPrice.setText(stringbuffer2.substring(0,stringbuffer2.length())); } return false; } }); setNumber(buffer,buffer2,etGoodsPrice,etoriginalPrice); tv_softkb_hIDdenkb.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { editPriceVIEw.clearanimation(); priceDialog.cancel(); } }); TextVIEw confirmKB = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_confirmKB); hIDdenSoftKB(etGoodsPrice,etoriginalPrice); confirmKB.setonClickListener(new OnClickListener() { @Suppresslint("NewAPI") @OverrIDe public voID onClick(VIEw v) { // iPriceEdit // ioldPriceEdit if (buffer != null) { // iPriceEdit.setText("¥"+buffer.toString()); iPriceEdit.setText("¥" + etGoodsPrice.getText().toString()); if (etGoodsPrice.getText().toString().equals("")) { iPriceEdit.setText("¥" + "0.00"); } } if (buffer2 != null) { // ioldPriceEdit.setText("¥"+buffer2.toString()); ioldPriceEdit.setText("¥" + etoriginalPrice.getText().toString()); if (etoriginalPrice.getText().toString().equals("")) { ioldPriceEdit.setText("¥" + "0.00"); } } if(etGoodsPrice.getText().toString().equals("")){ etGoodsPrice.setText("0.00"); } if(etoriginalPrice.getText().toString().equals("")){ etoriginalPrice.setText("0.00"); } if(Double.valueOf(etGoodsPrice.getText().toString())>Double.valueOf(etoriginalPrice.getText().toString())) { // Toast.makeText(PostIssueActivity.this,"售价高于原价,是否确认?",0).show(); PublicDialog PriceIsMaxDialog = PublicDialog.createDialog(PostIssueActivity.this,new DialogBtnClickListener() { @OverrIDe public voID onClick(VIEw vIEw) { switch (vIEw.getID()) { case R.ID.public_dialog_cancel: editPriceVIEw.clearanimation(); priceDialog.cancel(); break; case R.ID.public_dialog_confirm: editPriceVIEw.clearanimation(); priceDialog.cancel(); break; default: break; } } }); Window dialogwindow = PriceIsMaxDialog.getwindow(); display display = getwindowManager().getDefaultdisplay(); WindowManager.LayoutParams lp = dialogwindow.getAttributes(); lp.wIDth = (int) (display.getWIDth() * 0.99); dialogwindow.setAttributes(lp); PriceIsMaxDialog.show(); linearLayout llPublic = (linearLayout) PriceIsMaxDialog.findVIEwByID(R.ID.ll_public_dialog); llPublic.setBackground(getResources().getDrawable(R.drawable.public_dialog_botom_corner_shape_wite)); PriceIsMaxDialog.onWindowFocusChanged(true); // VIEw splitling = PriceIsMaxDialog.findVIEwByID(R.ID.v_line); // splitling.setBackgroundcolor(color.color_eaeaea); PriceIsMaxDialog.setlinecolor(color.parsecolor("#E9E9EB")); PriceIsMaxDialog.setTitle("提示"); PriceIsMaxDialog.setContent("出价高于原价,是否确认?"); PriceIsMaxDialog.setTitleVisibility(true); TextVIEw contentVIEw = PriceIsMaxDialog.getContentVIEw(); contentVIEw.setTextSize(16); contentVIEw.setGravity(Gravity.CENTER); contentVIEw.setpadding(0,10); androID.vIEw.VIEwGroup.LayoutParams layout = contentVIEw.getLayoutParams(); layout.wIDth = lp.MATCH_PARENT; layout.height = 120; contentVIEw.setLayoutParams(layout); TextVIEw publicdialogCancle = (TextVIEw) PriceIsMaxDialog.findVIEwByID(R.ID.public_dialog_cancel); publicdialogCancle.setText("否"); PriceIsMaxDialog.setCancelTextcolor(color.parsecolor("#037BFE")); // PriceIsMaxDialog.setCancelBackGround(color.parsecolor("#ffffff")); // publicdialogCancle.setTextcolor(color.app_green); TextVIEw publicdialogConfirm = (TextVIEw) PriceIsMaxDialog.findVIEwByID(R.ID.public_dialog_confirm); publicdialogConfirm.setText("是"); PriceIsMaxDialog.setConfirmTextcolor(color.parsecolor("#037BFE")); // PriceIsMaxDialog.setConfirmBackGround(color.parsecolor("#ffffff")); // publicdialogConfirm.setTextcolor(color.app_green); // publicdialogConfirm.setBackground(getResources().getDrawable(R.drawable.coners_save_bg)); PriceIsMaxDialog.findVIEwByID(R.ID.vv_hor).setVisibility(VIEw.VISIBLE); } editPriceVIEw.clearanimation(); priceDialog.cancel(); } }); } /** * 删除输入的金额 */ protected voID delNumber() { if (etGoodsPrice.hasFocus()) { // buffer.delete(0,etGoodsPrice.getText().length()); if (etGoodsPrice.getText().length() >= 1) { buffer.deleteCharat(etGoodsPrice.getText().length() - 1); // buffer.deleteCharat(etGoodsPrice.getText().length()); } stringbuffer = buffer.toString(); etGoodsPrice.setText(stringbuffer.substring(0,stringbuffer.length())); etGoodsPrice.setSelection(etGoodsPrice.length()); } if (etoriginalPrice.hasFocus()) { // buffer2.delete(0,etoriginalPrice.getText().length()); if (etoriginalPrice.getText().length() >= 1) { buffer2.deleteCharat(etoriginalPrice.getText().length() - 1); // buffer2.deleteCharat(etoriginalPrice.getText().length()); } stringbuffer2 = buffer2.toString(); etoriginalPrice.setText(stringbuffer2.substring(0,stringbuffer2.length())); etoriginalPrice.setSelection(etoriginalPrice.length()); } } /** * 输入金额 * * @param buffer * @param buffer2 * @param etGoodsPrice * @param etoriginalPrice */ private voID setNumber(final StringBuffer buffer,final StringBuffer buffer2,final EditText etGoodsPrice,final EditText etoriginalPrice) { TextVIEw tv_softkb_1 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_1); tv_softkb_1.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("1"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("1"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_2 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_2); tv_softkb_2.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("2"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("2"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_3 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_3); tv_softkb_3.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("3"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("3"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_4 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_4); tv_softkb_4.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("4"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("4"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_5 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_5); tv_softkb_5.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("5"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("5"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_6 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_6); tv_softkb_6.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("6"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("6"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_7 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_7); tv_softkb_7.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("7"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("7"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_8 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_8); tv_softkb_8.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("8"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("8"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_9 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_9); tv_softkb_9.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("9"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("9"); etoriginalPrice.setText(buffer2.toString()); } } }); TextVIEw tv_softkb_0 = (TextVIEw) editPriceVIEw.findVIEwByID(R.ID.tv_softkb_0); tv_softkb_0.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("0"); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("0"); etoriginalPrice.setText(buffer2.toString()); } } }); tv_softkb_point.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (etGoodsPrice.hasFocus()) { buffer.append("."); etGoodsPrice.setText(buffer.toString()); } if (etoriginalPrice.hasFocus()) { buffer2.append("."); etoriginalPrice.setText(buffer2.toString()); } } }); } /** * 使用edittext获取焦点d不出软件键盘 * * @param etGoodsPrice * @param etoriginalPrice */ private voID hIDdenSoftKB(final EditText etGoodsPrice,final EditText etoriginalPrice) { etGoodsPrice.setontouchListener(new OntouchListener() { @OverrIDe public boolean ontouch(VIEw v,MotionEvent event) { int inType = etGoodsPrice.getinputType(); // backup the input // type etGoodsPrice.setinputType(inputType.TYPE_NulL); // disable soft // input etGoodsPrice.ontouchEvent(event); // call native handler etGoodsPrice.setinputType(inType); // restore input type etGoodsPrice.setSelection(etGoodsPrice.getText().length()); return true; } }); etoriginalPrice.setontouchListener(new OntouchListener() { @OverrIDe public boolean ontouch(VIEw v,MotionEvent event) { int inType = etoriginalPrice.getinputType(); // backup the input // type etoriginalPrice.setinputType(inputType.TYPE_NulL); // disable // soft // input etoriginalPrice.ontouchEvent(event); // call native handler etoriginalPrice.setinputType(inType); // restore input type etoriginalPrice.setSelection(etoriginalPrice.getText().length()); return true; } }); } /** * 输入原价和价格dialog */ private voID showMofityPrice() { // Todo auto-generated method stub mofityPrice.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // iPriceEdit // ioldPriceEdit // iPriceEdit.setFocusable(true); hIDdenKeyboard(); editPriceDialog(); } }); }

以上所述是小编给大家介绍的AndroID开发仿咸鱼键盘修改版,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

总结

以上是内存溢出为你收集整理的Android开发仿咸鱼键盘DEMO(修改版)全部内容,希望文章能够帮你解决Android开发仿咸鱼键盘DEMO(修改版)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1147738.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存