I'm trying to convert TextView
to Drawable
to use it as a sticker in my app, but I have a problem, as you see in the picture below, The text becomes cut off from the right, to fix that I added two spaces like that:
When I add only one space like that textview.getText()+ " "
I get this :
When I add " " +textview.getText() + " "
,text disappears,I see only background :
after I do that, TextView
not showing at all when I convert it to Drawable
, here's the method to convert TextView
to Drawable
public static Bitmap loadBitmapFromView(View view) {
Bitmap createBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
view.draw(canvas);
return createBitmap;
}
textView.setText(" " + editText.getText() + " ");
Bitmap bitmap = loadBitmapFromView(textView);
loadSticker(bitmap);
XML :
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_horizontal|center_vertical"
android:padding="20dp"
android:scrollbars="vertical"
android:shadowColor="#fff"
android:shadowDx="4"
android:shadowDy="-4"
android:shadowRadius="1"
android:text="Your Text Here"
android:textColor="#000"
android:textSize="25sp"
android:textStyle="bold" />