如何启用Android的选择/复制文本? [英] how to enable select/copy texts in android?
问题描述
这是我的应用程序策略:
this is my app strategy:
- 有一个包含文本的文本视图。
- 编辑它们,我定义操作模式的项目(例如编辑 - 这将
文本视图的文本翻译成编辑文本)虽然也有一些默认
像选择所有动作/复制/ ..作为文本选择,所以我不不想
来定义它们。
我用这个code启用默认选择/复印按钮。
但是,当我点击的按钮,没有任何反应。为什么???
XML code:
i use this code for enabling the default selecting/copy buttons. but as i clicked the buttons, nothing happens. why??? xml code:
<TextView
android:id="@+id/speech"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:textSize="25sp" android:textAlignment="inherit"
android:selectAllOnFocus="true"
android:background="@drawable/curved_background"
android:layout_centerInParent="true" android:textIsSelectable="true"
android:padding="10dp" />
在初始化类TextView的:
initializing TextView in class:
speech_text = (TextView) findViewById(R.id.speech);
registerForContextMenu(speech_text);
speech_text.setTextIsSelectable(true);
speech_text.setCustomSelectionActionModeCallback(new SelectText());
SelectingText java类:
SelectingText java class:
public class SelectText implements ActionMode.Callback {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.text_select, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Log.d(Log, String.format("onActionItemClicked item=%s/%d", item.toString(), item.getItemId()));
switch (item.getItemId()) {
case ... //other actions
return true;
}
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
}
}
请注意:
当我控制我的code。问题是在这一行定义 SelectText
类: speech_text.setCustomSelectionActionModeCallback(新SelectText());
,因为正如我删除code,每一件事情worksgood!
Note:
as i control my code. the problem is in defining SelectText
class in this line: speech_text.setCustomSelectionActionModeCallback(new SelectText());
because as i delete thiscode, every thing worksgood!
推荐答案
您可以让您在应用程序的文本启用对剪贴板复制/粘贴通过添加以下行:
You can make your text in app enable for copy/paste in clipboard by adding below line :
android:textIsSelectable
有关详细信息,请参考下面,
http://developer.android.com/reference/android/widget/TextView.html
For more information, Please check below reference, http://developer.android.com/reference/android/widget/TextView.html
感谢。
这篇关于如何启用Android的选择/复制文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!