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 6375115
In Process

The Archive Base Latest Questions

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

Is there any way to make the text in an AlertDialog selectable or copyable

  • 0

Is there any way to make the text in an AlertDialog “selectable” or “copyable” in Android? Or do I have to use some other widget instead of AlertDialog?

  • 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:34:27+00:00Added an answer on May 25, 2026 at 1:34 am

    This can be achieved several ways. But first, to customize the dialog more, you’ll need to use the AlertDialog.Builder-class to create your custom dialog. This can then be populated by your own Views.

    Here are three methods of how you can archive your selectable text:

    Using Android 3.0 +

    Since API-Level 11 (Android 3.0), the TextView has a method called setTextIsSelectable(), which pretty much looks like what I achieved by hacking around as detailed below.

    // The TextView to show your Text
    TextView showText = new TextView(this);
    showText.setText("Some selectable text goes here.");
    showText.setTextIsSelectable(true);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // Build the Dialog
    builder.setView(showText)
           .setTitle("Selectable text")
           .setCancelable(true)
           .show();
    

    The problem with this solution is, that it will only work on devices running Android 3.0 and higher, while the other two solutions will also work on Android 1.5 (I used Android 2.2).

    Copy to Clipboard

    Since the purpose of marking text is (most of the time) to copy it, you can simply add an onLongClickListener or a simple onClickListener (the one you like the most) to the TextView and copy its displayed text to the System’s clipboard.

    Little illustration of this:

    // Get our tools
    AlertDialog dialog;
    AlertDialog.Builder builder;
    // The TextView to show your Text
    TextView showText = new TextView(this);
    showText.setText("Some selectable text goes here.");
    // Add the Listener
    showText.setOnLongClickListener(new View.OnLongClickListener() {
    
        @Override
        public boolean onLongClick(View v) {
            // Copy the Text to the clipboard
            ClipboardManager manager = 
                (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            TextView showTextParam = (TextView) v;
            manager.setText( showTextParam.getText() );
            // Show a message:
            Toast.makeText(v.getContext(), "Text in clipboard",
                    Toast.LENGTH_SHORT)
            .show();
            return true;
        }
    });
    // Build the Dialog
    builder = new AlertDialog.Builder(this);
    builder.setView(showText);
    dialog = builder.create();
    // Some eye-candy
    dialog.setTitle("Selectable text");
    dialog.setCancelable(true);
    dialog.show();
    

    This example will copy all the displayed text in the systems clipboard.

    Make an EditText look like a TextView

    Since there is no really easy way to make the Text of a TextView selectable on Android versions before 3.0, you can use an EditText (which has selectable text by default) and make it look like a TextView.

    This needs some XML-Layout (to get the TextView‘s style) but probably gets you the most native look and feel:

    The XML-Part:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <!-- Make the EditText look like a TextView -->
        <EditText android:id="@+id/showText"
            style="?android:attr/textViewStyle"
            android:background="@null"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
    
    </LinearLayout>
    

    The Java-Part:

    // Get our tools
    AlertDialog dialog;
    AlertDialog.Builder builder;
    // The EditText to show your Text
    LayoutInflater inflater = 
        (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.dialog,
            (ViewGroup) this.findViewById(R.id.showText));
    EditText showText = (EditText) layout.findViewById(R.id.showText);
    showText.setText("Some selectable text goes here.");
    // Build the Dialog
    builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    dialog = builder.create();
    // Some eye-candy
    dialog.setTitle("Selectable text");
    dialog.setCancelable(true);
    dialog.show();
    

    Some customizations and eye-candy might be added to the result 😉

    I hope this gives you an idea of how you can achieve this task. It’s late now, time for bed.

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

Sidebar

Related Questions

Is there any way to make the Tkinter Entry widget so that text can
is there any way to make IE6 understand double classes, say I have a
Is there any way to make some sections of the web.config file only apply
Is there any way to make all the applications on a server use SQL
Is there any way to make the text after a bullet in a ul
Is there any way to make the text in a Windows Form to scroll
Is there any way to make a part of a label.text to be bold?
Is there any browser based XHTML editor which we can use to make text
Is there any way to make Visual Studio 2008 Express store all the files
Is there any way to make Visual Studio word-wrap at 80 characters? I'm using

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.