1

I want to share some text on Facebook. But I want that my text should have some frame behind it / or image .

How can I set text on image and then share it?

Michael
  • 53,859
  • 22
  • 133
  • 139
M.satti
  • 31
  • 3
  • This thread different topic but explain simple text to drawable processing http://stackoverflow.com/questions/4318572/how-to-use-a-custom-typeface-in-a-widget – nurisezgin Apr 01 '16 at 11:01

3 Answers3

1

Use the text view and set background to it

android:background="@drawable/myResouce"

Or from within your code :

  mTextView.setBackgroundResource(R.drawable.myResouce);
2D3D
  • 353
  • 1
  • 6
  • 22
1

Create one layout and set the required background image, and have a textview inside that layout to set your text.

Then inside your java code get this and covert it to bitmap.

FrameLayout view = (FrameLayout)findViewById(R.id.framelayout);

view.setDrawingCacheEnabled(true);

view.buildDrawingCache();

Bitmap bm = view.getDrawingCache();

Then u can share this bitmap to facebook

Ankit
  • 101
  • 5
1

Well the right way to do it would be to make a custom control named MyImageTextView extends View and use onDraw method to draw image and text on it using canvas.

public class MyImageTextView extends View {
     String textOnImage;
     Bitmap bitmapBackground;

     public MyImageTextView(Context context) {
         super(context);
         init();
     }

     public MyImageTextView(Context context, AttributeSet attrs) {
         super(context, attrs);
         init();
     }


     public MyImageTextView(Context context, AttributeSet attrs, int defStyleAttr)
     {
         super(context, attrs, defStyleAttr);
         init();
     }

     @Override
     protected void onDraw(Canvas canvas) {
         // TODO Auto-generated method stub
         super.onDraw(canvas);

         int centerx = getWidth() / 2;
         int centery = getHeight() / 2;

         canvas.drawBitmap(bitmapBackground, 0, 0, null);
         drawText(canvas, centerx , centery , textOnImage)
     }

     public void drawText(Canvas canvas, float x, float y, String text) {
         int consumedCalTextSize =      getResources().getDimensionPixelSize(R.dimen.food_circular_graph_text_size);
        Paint canvasTextPaint = new Paint();
        canvasTextPaint.setAntiAlias(true);
        canvasTextPaint.setARGB(255, 255, 255, 255);
        canvasTextPaint.setTextSize(consumedCalTextSize);
        canvasTextPaint.setTextAlign(Paint.Align.CENTER);
        canvas.drawText(text, x, y, canvasTextPaint);
    }
}

You can have full access to modify this custom control and also you can add it in your XML. Android controls are really powerful that way.

Nanites
  • 410
  • 3
  • 16
  • The logic about where you want to draw your image, I think it would be central to the control, can be modified as well. – Nanites Apr 01 '16 at 13:04