Android Open Source - advanced-textview Lined Edit Text






From Project

Back to project page advanced-textview.

License

The source code is released under:

Apache License

If you think the Android project advanced-textview listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.sqisland.android.advanced_textview.widget;
/* ww w  .  j a v a2s. c  o m*/
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.EditText;

import com.sqisland.android.advanced_textview.R;

public class LinedEditText extends EditText {
  private Paint paint = new Paint();

  public LinedEditText(Context context) {
    super(context);
    init();
  }

  public LinedEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  public LinedEditText(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
  }

  private void init() {
    paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(getResources().getColor(R.color.paper_line));
    paint.setStrokeWidth(getLineHeight() / 10);
    paint.setStrokeCap(Paint.Cap.ROUND);
  }

  @Override
  protected void onDraw(Canvas canvas) {
    float startX = getPaddingLeft();
    float stopX = getWidth() - getPaddingRight();
    float offsetY = getPaddingTop() - getPaint().getFontMetrics().top + paint.getStrokeWidth() / 2;

    for (int i = 0; i < getLineCount(); ++i) {
      float y = offsetY + getLineHeight() * i;
      canvas.drawLine(startX, y, stopX, y, paint);
    }

    super.onDraw(canvas);
  }
}




Java Source Code List

com.sqisland.android.advanced_textview.AboutActivity.java
com.sqisland.android.advanced_textview.AlignmentSpanActivity.java
com.sqisland.android.advanced_textview.AnimatedCompoundDrawableActivity.java
com.sqisland.android.advanced_textview.AnimatedRainbowSpanActivity.java
com.sqisland.android.advanced_textview.ClickableSpanActivity.java
com.sqisland.android.advanced_textview.CustomFontActivity.java
com.sqisland.android.advanced_textview.EmojiActivity.java
com.sqisland.android.advanced_textview.FractionActivity.java
com.sqisland.android.advanced_textview.FromHtmlActivity.java
com.sqisland.android.advanced_textview.GradientTextActivity.java
com.sqisland.android.advanced_textview.LinedPaperActivity.java
com.sqisland.android.advanced_textview.MainActivity.java
com.sqisland.android.advanced_textview.PatternedTextActivity.java
com.sqisland.android.advanced_textview.RainbowSpanActivity.java
com.sqisland.android.advanced_textview.ShadowTextActivity.java
com.sqisland.android.advanced_textview.StyledStringActivity.java
com.sqisland.android.advanced_textview.widget.LinedEditText.java