Exploring Android 13: Copy and Paste Improvements
Android 13 (Tiramisu)’s new APIs and features are ready to be tried out by developers. One of them is a copy and paste improvements.
Copy and paste gets an improvement in Android 13 by the addition of a standardized UI shown when a content is copied to clipboard.
As you can see in the image below, now you don’t need to show a Toast/Snackbar anymore to inform the user that a content is copied.
In this article, we are going to create a simple app that utilizes this new feature.
Where’s the Source Code?
Step by Step Explanation
Follow the steps provided below to make this application.
1. As of the writing of this article, Android 13 can only be used with the preview release of Android Studio. Therefore, you must go to this page, and download the Canary Build of Android Studio.
2. Once installed, you need to install the Android 13 SDK. You can do this by clicking Tools > SDK Manager. In the SDK Platforms tab, select Android 13. In the SDK Tools tab, select Android SDK Build-Tools 33. Click OK to install the SDK.
3. Once SDK is installed, open the Android Studio. Create new project with Empty Activity option.
4. First off, you need to change the target and compile SDK version of this app. Open app/build.gradle
and you would see something like this:
Change the compileSdk
and targetSdk
to use the Android 13 SDK like shown in the code snippet below. Don’t forget to click Sync Now after.
5. Next, let’s create our layout first. Open activity_main.xml
and update the content to this:
The layout contains two buttons. The first button will copy a plain text and the second one will copy a confidential text. The image below shows how the layout will look like.
6. Finally, we will update our MainActivity.kt
file. You can go ahead and copy paste the code snippet below. The most important thing to notice here is that we only need to show Snackbar for devices running Android 12 and lower. Also, notice how you can mark the text as sensitive so that it won’t be shown in the UI preview.
7. That’s it! Now try running your app and you should get something like this:
Whenever a content is copied to clipboard, a standardized UI will appear at bottom-left corner of the screen. You can edit the copied text by clicking the UI. Also notice how the UI will obscure the copied text when it’s marked as sensitive.
As always, thanks for reading!
Want to learn more about Android 13?
Check out all of our articles from “Exploring Android 13” series here: