这是我的应用策略:
我使用此代码启用默认的选择/复制按钮。但是当我点击按钮的时候,什么都没发生。为什么?xml代码:
<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:
speech_text = (TextView) findViewById(R.id.speech);
registerForContextMenu(speech_text);
speech_text.setTextIsSelectable(true);
speech_text.setCustomSelectionActionModeCallback(new SelectText());
SelectingText java类:
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) {
}
}
注意:当我控制我的代码。问题是在这一行中定义SelectText
类:speech_text.setCustomSelectionActionModeCallback(new SelectText());
,因为当我删除这段代码时,每件事情都很好!
发布于 2016-05-05 06:41:03
您可以通过添加以下行,使应用程序中的文本能够在剪贴板中复制/粘贴:
android:textIsSelectable
有关更多信息,请查看下面的参考资料,http://developer.android.com/reference/android/widget/TextView.html
谢谢。
发布于 2022-01-02 01:03:05
这应该对你有用。在您的xml jus中确保..。
android:focusable="true"
android:textIsSelectable="true"
https://stackoverflow.com/questions/37052973
复制