经过漫长而耗时的搜索,我找不到一个可以在textview中为android API级别<= 11选择文本的组件.我写过这个可能对你有所帮助的组件:
public class SelectableTextView extends TextView {
public static int _SelectedBackgroundColor = 0xffA6D4E1;
public static int _SelectedTextColor = 0xff000000;
private OnTouchListener lastOnTouch;
protected int textOffsetStart;
protected int textOffsetEnd;
private OnLongClickListener lastOnLongClick;
protected boolean longCliked;
protected boolean isDowned;
protected int textSelectedEnd;
protected int textSelectedStart;
private static SelectableTextView lastInstance;
public SelectableTextView(Context context) {
super(context);
}
public void setTextIsSelectable(boolean selectable) {
// TODO:ANDROID3
// if:androidversion>=3
// super.setTextIsSelectable(selectable);
// else
super.setLongClickable(true);
super.setOnLongClickListener(getSelectableLongClick());
super.setOnTouchListener(getSelectableOnTouch());
}
private OnLongClickListener getSelectableLongClick() {
return new OnLongClickListener() { …Run Code Online (Sandbox Code Playgroud)