How To Implement Copy/Paste in Android Using TextView

Implement copy/paste in your TextView in Android programmatically

Mustufa Ansari
Sep 15 · 2 min read
Photo by Matam Jaswanth on Unsplash

In this article I’ll show you how to implement copy paste text from TextView in your Android app. EditText has built-in functionality whereby you can easily copy text through a long press but in the TextView, that might not be the case. We need to write some code to achieve the same functionality using our TextView.

Let’s get started!

You can check out the official documentation about Copy-Paste in Android here.

Step 1:

We’re making a simple app so I am starting with basic layout with one TextView.

In you onCreate() initialize your TextView and call registerForContextMenu() method and pass your TextView in it.

According to the documentation registerForContextMenu() helps to register a context menu to be shown for the given view, because we need a menu to select a “Copy” option that will pop up on a long press.

Step 2:

Now to override a method onCreateContextMenu() , which will help us achieve our goal.

Now let’s run the app:

Copy paste android functionality

Better Programming

Advice for programmers.

Mustufa Ansari

Written by

📱Mobile Application Developer 🎓Keen Learner 🎓Graduate 🎧Love Music 🎓 Tech Enthusiast!

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade