Android Marshmallow provides a new way to handle selected text in any Android application. To select text in Android application, long hold on a word then a blue color appear to adjust your text selection (we can drag them word by word) . Now a toolbar at the top with obscure icons representing cutting, copying and pasting. You can also paste copied text on any other application.
In this tutorial, we will learn how to implement Text Selection in Android application. We would have to long hold on word to select text, when you hold on word then a toolbar appear at the top with option copy, cut and paste. We need to choose any of the one option to be perform operation. We can also paste copied text in any other application. For that, only we need to intent-filter in the <activity> section in AndroidManifest.xml file.
Add Intent Filter
To enable Text Selection behavior in Android Application, we need to add intent filter in the <activity> section in AndroidManifest.xml file. Manifest file look like this:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.textselection"> <application> ...... <intent-filter > <action android:name="android.intent.action.PROCESS_TEXT"/> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </intent-filter> </activity> </application> </manifest>
To select text, we need to add bufferType=”spannable” and textIsSelectable=”true” in TextView.
<TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:bufferType="spannable" android:textIsSelectable="true" android:text="Long hold to select text and we can copy it and paste in any other application" />
- Android Facebook Integration and Login Tutorial - February 11, 2017
- Android Application Integrate to Amazon S3 Tutorial - January 26, 2017
- Android – Integrate Google AdMob in Android Application Tutorial - January 19, 2017
- Android Bar Code/ QR-Code Scanner Tutorial using ZXING Scanner Library - January 12, 2017
- Android Bar Code/ QR-Code Generator Tutorial Using ZXING Library - January 5, 2017
- Android PhoneStateListener/ Phone Call Broadcast Receiver Tutorial - December 26, 2016
- Android Pie Chart using MpAndroid Library Tutorial - November 29, 2016
- Android Bar Chart or Bar Graph using MpAndroid Library Tutorial - October 16, 2016
- How to Post Data Using AJAX and PHP Tutorial - October 16, 2016
- How to submit a form using JQuery Ajax and PHP - October 16, 2016