SoFunction
Updated on 2025-03-10

How to remove borders and add underscores in EditText in Android

I won’t say much nonsense, I will just post code to everyone.

<span style="font-family: Arial, Helvetica, sans-serif;"><?xml version="1.0" encoding="utf-8"?> 
</span> 
<LinearLayout xmlns:andro 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<!--Note the name --> 
< 
android: 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
style="?android:attr/textViewStyle" 
android:background="@null" 
android:textColor="@null" 
/> 
</LinearLayout> 

The background can be set to other colors, etc.

textColor does not have to be null, you can set the font color

Add underline

public class LineEditText extends EditText { 
// Brush is used to draw underlinesprivate Paint paint; 
public LineEditText(Context context, AttributeSet attrs) { 
super(context, attrs); 
paint = new Paint(); 
(); 
(); 
// Turn on anti-aliasing, consumes memory(true); 
} 
@Override 
protected void onDraw(Canvas canvas) { 
(canvas); 
// Get the total number of rowsint lineCount = getLineCount(); 
// Get the height of each rowint lineHeight = getLineHeight(); 
//Draw lines according to the number of linesfor (int i = 0; i < lineCount; i++) { 
int lineY = (i + 1) * lineHeight; 
(0, lineY, (), lineY, paint); 
} 
} 
}

The above content introduces you to how to remove borders and add underscores in EditText in Android. I hope it will be helpful to everyone!