开发者

Select text from TextView?

开发者 https://www.devze.com 2023-02-10 14:04 出处:网络
Is it possible to se开发者_如何转开发lect text from a TextView(including highlight) ? It is possible with EditText but i need that to be done using TextView ..

Is it possible to se开发者_如何转开发lect text from a TextView(including highlight) ?

It is possible with EditText but i need that to be done using TextView ..

Any help regarding this please ?

Thanks,


Use this:

android:textIsSelectable="true"

as easy as pie ;)

Edit:

setting it in code: textView.setTextIsSelectable(true)


Not sure exactly what you are going for, and this may not be exactly what you want, but you can register it for a ContextMenu and then use onCreateContextMenu and the CLIPBOARD_SERVICE:

private TextView mTextView;

protected final void onCreate(Bundle savedInstanceState) {
...
registerForContextMenu(mTextView);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
        TextView textView = (TextView) view;
        menu.setHeaderTitle(textView.getText()).add(0, 0, 0, R.string.menu_copy_to_clipboard);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    ((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText(mTextView.getText());
    return true;
}


Actually, you do not have to develop this feature by yourself. You just need to use EditText instead TextView, while you set the android:editable of EditText to false.

My answer is here, hope it may help you:

https://stackoverflow.com/a/11026292/966405

0

精彩评论

暂无评论...
验证码 换一张
取 消