EditTextカスタムアンダースコア



Edittext Custom Underline



カスタムEditTextコードは次のとおりです。 (それでも記事で問題を解決できない場合は、EditTextカスタムアンダースコア-詳細バージョンに移動してください) public class LineEditext extends EditText { // Pen is used to draw underline private Paint paint public LineEditext(Context context, AttributeSet attrs) { super(context, attrs) paint = new Paint() paint.setStyle(Paint.Style.STROKE) paint.setColor(Color.RED) // Turn on anti-aliasing, which consumes more memory paint.setAntiAlias(true) } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas) // Get the total number of rows int lineCount = getLineCount() // get the height of each row int lineHeight = getLineHeight() // Get the physical length of the text in EditText TextPaint mTextPaint = getPaint() float textWidth = mTextPaint.measureText(getText().toString()) // Draw lines according to the number of lines for (int i = 0 i
paint.setAntiAlias(true)
1.setAntiAlias()
TextPaint mTextPaint = getPaint() floattextWidth = mTextPaint.measureText(getText().toString()) 以下を参照できます。 http://blog.csdn.net/lovexieyuan520/article/details/50732023
2. EditTextテキストの物理的な長さを取得する方法: canvas.drawLine(0, lineY, this.getWidth(), lineY, paint)
3.もちろん、編集テキストの下線の幅全体をカバーしたい場合は、次のこともできます。 使用する TextPaint mTextPaint = getPaint() floattextWidth = mTextPaint.measureText(getText().toString()) 交換
|_+_|
それでおしまい。 効果は次のとおりです。