这篇博客用来记录日常开发和工作中遇到的小问题以及解决办法。。。
(问题一)隐藏软键盘问题----软键盘弹出后,页面刷新软键盘没有隐藏
解决代码:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
mEditText为当前获取到焦点的输入框
(问题二)Bitmap和Drawable之间的相互转换
⒈Bitmap转换成Drawable
Bitmap bm = xxxxx;
Drawable mDrawable = new BitmapDrawable(bm);
⒉Drawable转换成Bitmap
Drawable d=xxxxx;
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd.getBitmap();
或者
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.d);
⒊EditText保留2位小数
首先在values文件夹的strings.xml文件中定义以下规则
<string name="amount_format">%.2f</string>
然后在EditText设置值:
mEdit.setText(String.format(getString(R.string.amount_format), 21.99999));