Android TextView长按复制实现

自定义textview

import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;

public class NewTextView extends EditText {
    public NewTextView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public NewTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public NewTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected boolean getDefaultEditable() {//禁止EditText被编辑
        return false;
    }
}

layout文件应用

<com.administrator.myhp.NewTextView
    android:id="@+id/totwo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null"
    android:text="Hello World!" />

Java代码

NewTextView textView = (NewTextView) findViewById(R.id.totwo);
textView.setTextIsSelectable(true);

猜你喜欢

转载自blog.csdn.net/meixi_android/article/details/80967097