I am saving my layout to a bitmap, which contains an ImageView and an EditText.
I am using this code:
public void saveToImage(RelativeLayout content){
Bitmap bitmap = Bitmap.createBitmap(content.getWidth(), content.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
content.layout(0, 0, content.getLayoutParams().width, content.getLayoutParams().height);
content.draw(c);
try{
File file,f = null;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
file =new File(android.os.Environment.getExternalStorageDirectory(),"TTImages_cache");
if(!file.exists())
{
file.mkdirs();
}
f = new File(file.getAbsolutePath()+file.separator+ "filename"+".png");
}
FileOutputStream ostream = new FileOutputStream(f);
bitmap.compress(CompressFormat.PNG, 10, ostream);
ostream.close();
}
catch (Exception e){
e.printStackTrace();
}
}
However the image I save looks like this:
I would like to remove the underlined text and the text cursor in the edittext when saving the bitmap. Is that possible?
To remove the blinking cursor before saving the bitmap you can do
editText.setCursorVisible(false);
And then set it back to true again afterwards.
You just need to remove both underline and cursor when you start capturing the layout. You can remove the underline by:
yourEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
and the cursor by:
yourEditText.setCursorVisible(false);
It would be better if you disable the cursor inside your saveToImage method by:
public void saveToImage(RelativeLayout content){
yourEditText.setCursorVisible(false);
....
....
//your code for saving the layout
}
and then after the layout is saved in the memory, just reset the yourEditText to show the cursor.
public void saveToImage(RelativeLayout content){
//your code for saving the layout
....
....
yourEditText.setCursorVisible(true);
}
来源:https://stackoverflow.com/questions/23677895/saving-an-edittext-to-bitmap