2014-12-02 6 views
0

메모장처럼 보이는 EditText 사용자 정의가 있습니다. 그 점에서 라이브 문자 수를 보여줄 필요가 있습니다 아무도 나를 도와 줄 수 있습니까?메모장의 라이브 문자 수 EditText android

LineEditText.java

public class LinedEditText extends EditText { 
    private Rect mRect; 
    private Paint mPaint; 
    int initialCount=10 
    @SuppressLint("NewApi") 
    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.parseColor("#C0C0C0")); //SET YOUR OWN COLOR HERE 
    /*initialCount=getMinLines(); 
    setLines(initialCount);*/ 
} 

@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 레이아웃

<com.rb.lined.edittext.LinedEditText 
       android:id="@+id/edit_story" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"     
       android:background="@null" 
       android:inputType="textMultiLine|textNoSuggestions" 
       android:minLines="5" 
       android:singleLine="false" 
       android:imeOptions="actionNone" 
       android:text="" 
       android:textSize="13sp" 
       android:gravity="top|left" 
       android:layout_below="@+id/txt_story" 
       app:typeface="roboto_condensed" 
       android:maxLength="180"/> 

답변

0

Android Developer - TextView @ addTextChangedListener

사용자 정의 그것이 onDraw이 방금 문자가 계산 그릴이 여러 번 호출됩니다 쉽게 볼 사용하고 있기 때문에. 같은 수행 : 당신이 그래서 만약

canvas.drawText (getText().toString().length(), positionx, positiony, textPaint); 

편집

X를 Y는이 행해져 Yout 텍스트의 기원이 될 것이다 :

Paint myPaint = new Paint(); 
myPaint.setColor(Color.WHITE); 
myPaint.setTextAlign(Paint.Align.CENTER); 

positionx = getWidth()/2; 
positiony = getHeight()/2; 

canvas.drawText (getText().toString().length(), positionx, positiony, textPaint); 

이 중앙에 exacltly 텍스트를 그릴 것입니다 너의 견해.

+0

x와 y 위치로 나를 도울 수 있습니까? –

+0

@KarthikKolanji 참조 편집 – TheRedFox