Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6372523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:15:00+00:00 2026-05-25T01:15:00+00:00

In my android app I need to display a text on an image. The

  • 0

In my android app I need to display a text on an image. The text is entered by user in an alertDialog. This text I need to center it on the bottom of the image. I draw the text on image with this :

private Canvas drawTextImage(Bitmap b) {
        Canvas c = new Canvas(b);
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.orange));

        paint.setStrokeWidth(30);
        paint.setAntiAlias(true);
        paint.setTextSize(40);
        c.drawText(text, 350, 900, paint);

        c.translate(300, 50);
        return c;
    }

My alertDiallg is this :

        final AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Enter a text ");
    final EditText input = new EditText(this);
    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(25);
    input.setFilters(FilterArray);

    alert.setView(input);
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            text = input.getText().toString().trim();
            Canvas c = new Canvas(bitmapResult);
            drawTextImage(bitmapResult);
            saveimage();
        }
    });

    alert.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                    saveimage();
                }
            });

    alert.show();

Tehe text has to be center according to it’s length. How can I do this?

Thanks in advance..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:15:01+00:00Added an answer on May 25, 2026 at 1:15 am

    Use

    Paint.setTextAlign(Paint.Align.CENTER);
    

    on the paint thats used to draw your text.

    public void setTextAlign (Paint.Align align)

    Set the paint’s text alignment. This controls how the text is
    positioned relative to its origin. LEFT align means that all of the
    text will be drawn to the right of its origin (i.e. the origin
    specifieds the LEFT edge of the text) and so on.

    Source


    Edit: In draw text you have to specify half the with of your image as the x-coordinate (center), the y-coordinate should stay the same (somewhere along the bottom, depending how high you want it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an android app in which i need to display images after
I am now working on an android app in which I need to display
In my android app the user can enter the text in the EditView and
In my android app I need to display in a gridview images from a
I need table with editable cells for my Android app. Something like QTableWidget in
I'm building a mobile web app targeting Android users. I need to know what
I'm building an Android app and I want to copy the text value of
I've got an Android app which has a periodic background Service. I want this
I'm developing an android app, I've requirement to show the user current location and
I am working on an Android app that has multiple screens the user will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.