我正在做一个丝网打印并将其作为电子邮件附件发送。然而,丝网打印通常有一个空白的底部区域,大约是软键盘的大小。但是,我在屏幕截图前隐藏了键盘,它在屏幕上不可见。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_mail:
hideKeyboard();
View v = getWindow().getDecorView().getRootView();
v.setDrawingCacheEnabled(true);
myBitmap = v.getDrawingCache();
saveBitmap(myBitmap);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void saveBitmap(Bitmap bitmap) {
String filePath = Environment.getExternalStorageDirectory()
+ File.separator + Consts.SCREENSHOT_PATH_FILENAME;
File imagePath = new File(filePath);
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
sendMail(filePath);
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
public void hideKeyboard() {
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm =(InputMethodManager getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
然后将其作为电子邮件附件发送。知道如何去除屏幕打印中软键盘大小的空白吗?
最佳答案
好的,以下似乎有效。就在行之后:
View v = getWindow().getDecorView().getRootView();
我补充说:
v.invalidate();
我不能发誓这会解决问题,但在进行此更改后问题没有再次出现。过去,在隐藏键盘和创建位图后,屏幕似乎并不总是被重绘,从而在键盘所在的屏幕上留下一个“空白”点。
关于android - 只得到部分屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374975/