我在链接Custom EditText
中使用了自定义EditText
,例如记事本
在自定义EditText上输入的文本在其包含的行上无法正确显示。有一段时间出现在线上或线下,意外行为
我的输出 Click here !
必需输出 Click here !
请在这种情况下帮助我。
LineEditText.java
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.parseColor("#C0C0C0")); //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);
}
}
layout.xml
<RelativeLayout android:id="@+id/rel_edit_story"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_image"
android:padding="10dip"
android:layout_margin="10dip"
android:background="@drawable/relative_lined_edittext_border">
<com.rb.lined.edittext.LinedEditText
android:id="@+id/edit_story"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:inputType="textMultiLine|textNoSuggestions"
android:minLines="10"
android:singleLine="false"
android:imeOptions="actionNone"
android:text="Story : " />
</RelativeLayout>
答案 0 :(得分:1)
对于Desabeling Red下划线,你可以像
一样android:inputType="textNoSuggestions"
或
android:inputType="textVisiblePassword"
并且为了消除蓝线,这可能有所帮助。
android:background="@null"
实施例
<com.example.lineedittextdemo.LineEditText
android:id="@+id/edit_story"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="@null"
android:inputType="textMultiLine|textNoSuggestions"
android:minLines="10"
android:singleLine="false"
android:imeOptions="actionNone"
android:text="Story : \n" />