Skip to content

Instantly share code, notes, and snippets.

@francisnnumbi
Forked from lifeparticle/LICENSE
Created May 16, 2017 00:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francisnnumbi/546b316bb629fcb3bc634962458ea8b5 to your computer and use it in GitHub Desktop.
Save francisnnumbi/546b316bb629fcb3bc634962458ea8b5 to your computer and use it in GitHub Desktop.
Custom Edittext with Line Number

Custom Edittext with Line Number

Mou icon

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<rupantor.cusedittext.MyEditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</ScrollView>
package rupantor.cusedittext;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.EditText;
/**
* Author S Mahbub Uz Zaman on 5/9/15.
* Lisence Under GPL2
*/
public class MyEditText extends EditText {
private Rect rect;
private Paint paint;
public MyEditText(Context context, AttributeSet attrs) {
super(context, attrs);
rect = new Rect();
paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.BLACK);
paint.setTextSize(20);
}
@Override
protected void onDraw(Canvas canvas) {
int baseline = getBaseline()
for (int i = 0; i < getLineCount(); i++) {
canvas.drawText("" + (i+1), rect.left, baseline, paint);
baseline += getLineHeight();
}
super.onDraw(canvas);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment