J'ai le code suivant à mon avis personnalisé qui étend EditText:Comment définir drawable sur l'arrière-plan de View? Android
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int count = getLineCount();
Canvas cvs= new Canvas();
Drawable dr = this.getBackground();
Rect r = mRect;
Paint paint = mPaint;
mTextPaint.setTextSize(this.getTextSize());
Paint PaintText = mTextPaint;
for (int i = 0; i < count; i++) {
int baseline = getLineBounds(i, r);
cvs.drawText(Integer.toString(i+1), r.left, baseline + 1, PaintText);
cvs.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
}
cvs.drawLine(PaintText.measureText(Integer.toString(count)), this.getTop(), PaintText.measureText(Integer.toString(count)), this.getBottom(), paint);
dr.setBounds(0, 0, this.getRight(), this.getBottom());
dr.draw(cvs);
this.setBackgroundDrawable(dr);
}
Pourquoi est-il rien sur backgroind de ce point de vue?
Je suis content que vous ayez résolu le problème. – Michael