我正在尝试复制粘贴应用程序的editText的内容。
不幸的是它不起作用,似乎这不是一个常见的问题。
我怀疑是一个愚蠢的理由,但仍然无法找到原因。以防万一这是我的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<com.adylitica.customlistview.CustomLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/default_enlightenment"
android:orientation="horizontal" >
<com.adylitica.components.EditTextNotes
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@null"
android:paddingBottom="25dp"
android:paddingTop="10dp"
android:textColor="#301e1b"
android:textSize="24dp" />
<TextView
android:id="@+id/time"
android:layout_width="82dp"
android:layout_height="65dp"
android:background="@drawable/circle_background"
android:gravity="center"
android:textColor="@drawable/color_text"
android:textSize="18dp" />
以下是扩展EditText的组件代码:
package com.adylitica.components;
import com.adylitica.activity.R;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
/**
* Defines a custom EditText View that draws lines between each line of text that is displayed.
*/
public class EditTextNotes extends EditText {
private Context contextP;
private Rect mRect;
private Bitmap line;
public static int nbLines = 0;
public EditTextNotes(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
contextP = context;
line = BitmapFactory.decodeResource(contextP.getResources(), R.drawable.line_thin);
line = Bitmap.createBitmap(line, 0, 0, 2000, 1);
mRect = new Rect();
}
public EditTextNotes(Context context, AttributeSet attrs) {
super(context, attrs);
contextP = context;
line = BitmapFactory.decodeResource(contextP.getResources(), R.drawable.line_thin);
line = Bitmap.createBitmap(line, 0, 0, 2000, 1);
mRect = new Rect();
}
public EditTextNotes(Context context) {
super(context);
contextP = context;
line = BitmapFactory.decodeResource(contextP.getResources(), R.drawable.line_thin);
line = Bitmap.createBitmap(line, 0, 0, 2000, 1);
mRect = new Rect();
}
@Override
protected void onDraw(Canvas canvas) {
int count = getLineCount();
Rect r = mRect;
int baseline = 0;
int addSize = 0;
canvas.drawBitmap(line, 0, baseline, null);
for (int i = 0; i < count; i++) {
baseline = getLineBounds(i, r) + addSize;
canvas.drawBitmap(line, 0, baseline, null);
nbLines++;
}
super.onDraw(canvas);
}
}
P.S:否则editText的行为是好的,就像我可以得到焦点,写入...我只是无法选择整个文本并复制它。