public class LinedEditText extends EditText {
private Rect mRect;
private Paint mPaint;
// we need this constructor for LayoutInflater
public LinedEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(Color.BLACK); //SET YOUR OWN COLOR HERE
}
@Override
protected void onDraw(Canvas canvas) {
//int count = getLineCount();
int height = getHeight();
int line_height = getLineHeight();
int count = height/line_height;
if (getLineCount() > count)
count = getLineCount();//for long text with scrolling
Rect r = mRect;
Paint paint = mPaint;
int baseline = getLineBounds(0, r);//first line
for (int i = 0; i < count; i++) {
canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
baseline += getLineHeight();//next line
}
super.onDraw(canvas);
}
** Я использую этот класс для редактирования текста и могу изменить свойства в xml, но я не получаю ссылку на этот пользовательский редактировать текст. Как я могу получить ссылку на этот текст редактирования правильно в java? мой xml выглядит следующим образом **Получить ссылку в java-коде для изменения цвета текста и цвета фона пользовательского текста редактирования
<com.example.goh2.pronoornotepad.LinedEditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#ffff1904"
android:background="#ffffcc4b"
android:gravity="top|left"
android:singleLine="false"
android:id="@+id/et_textEditor"
android:text=""
/>
Да, я сделал это ... но im получаю исключение null указателя, когда я устанавливаю цвет фона lik myview.setbackgroundcolor (Color.Black) –