Select text from textview on one click in android

后端 未结 3 1283
花落未央
花落未央 2020-12-19 21:26

In one touch i want to get a option to select and copy the text from textview like the image show here.

\"enter

相关标签:
3条回答
  • 2020-12-19 21:31

    Just Set "textIsSelectable" on the TextView to true

        <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Detail Text"
                    android:id="@+id/txtBody"
                    android:background="@android:color/white"
                    android:gravity="right"
                    android:textColor="@android:color/black"
                    android:textSize="16sp"
                    android:padding="5dp"
                    android:enabled="true"
                    android:textIsSelectable="true"/>
    
    0 讨论(0)
  • 2020-12-19 21:44

    In your onClickListener for the TextView:

    ClipboardManager clipboard =
        (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
    clipboard.setText(yourTextView.getText());
    

    ed : Answer to the question in comments :

      yourTextView.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO: add your code here
    
            }
        });
    
    0 讨论(0)
  • 2020-12-19 21:45

    just add this to your TextView xml file :

    android:textIsSelectable="true"
    
    0 讨论(0)
提交回复
热议问题