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
?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You could place an EditText in your AlertDialog. If you didn't want it to seem like there's a textbox in there, you could just style it like the background of the AlertDialog to make it blend in.
http://developer.android.com/guide/topics/ui/dialogs.html
Hopefully that helps, if not, I can try to provide other means of a solution.
This is a bit hackish because it assumes you know the default AlertDialog layout (see Where can I find default AlertDialog layout xml file?), but if you want to go this way, you could do the following thing:
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 ownView
s.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 calledsetTextIsSelectable()
, which pretty much looks like what I achieved by hacking around as detailed below.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 simpleonClickListener
(the one you like the most) to theTextView
and copy its displayed text to the System's clipboard.Little illustration of this:
This example will copy all the displayed text in the systems clipboard.
Make an
EditText
look like aTextView
Since there is no really easy way to make the Text of a
TextView
selectable on Android versions before 3.0, you can use anEditText
(which has selectable text by default) and make it look like aTextView
.This needs some XML-Layout (to get the
TextView
's style) but probably gets you the most native look and feel:The XML-Part:
The Java-Part:
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.