自定义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);