Disable EditText blinking cursor
You can use either the xml attribute android:cursorVisible="false"
or programatically:
- java:
view.setCursorVisible(false)
- kotlin:
view.isCursorVisible = false
remove cursor from editText
to remove the cursor from edittext you need to set
nameText.setFocusable(false);
and to visible cursor set
nameText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
nameText.setFocusableInTouchMode(true);
return false;
}
});
will show the cursor in edittext...
Android EditText - Stop cursor blinking, want a solid cursor
Okay, seems the API does not allow a static cursor. I created my own extension of the AutoCompleteTextView which renders a cursor which never blinks. (You can use the same code to extend a noemal EditText or other derivative)
Bewarned if you want to have a multiline edit text then the height parameters will need some extra work. I have assumed one line and centered the height on the text box.
public class AutoCompleteEditTextStaticCursor extends AutoCompleteTextView {
private int mCursorColor = Color.BLACK; //Cursor defaults to black
private
int mStroke = 5; //Default stroke is 5
public AutoCompleteEditTextStaticCursor(Context context) {
super(context);
setCursorVisible(false);
}
public AutoCompleteEditTextStaticCursor(Context context, AttributeSet attrs){
super(context, attrs);
setCursorVisible(false);
}
public AutoCompleteEditTextStaticCursor(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
setCursorVisible(false);
}
/**
* Set the cursor color
* Must have a static int reference.
* If you wish to use a resource then use the following method
* int color = getResources().getColor(R.color.yourcolor);
*
* Default value Color.BLACK
* @param color
*/
public void setCursorColor(int color){ //Cursor defaults to black
mCursorColor = color;
}
/**
* Set the cursor stroke width
*
* Default value is 5
* @param stroke
*/
public void setCursorStroke(int stroke){
mStroke = stroke;
}
@Override
protected void onDraw(Canvas canvas) {
//Take this opportunity to draw our cursor
canvas = drawCursor(canvas);
super.onDraw(canvas);
}
/**
* Draw a cursor as a simple line,
* It would be possible to render a drawable if you wanted rounded corners
* or additional control over cursor
*
* @param canvas
* @return
*/
private Canvas drawCursor(Canvas canvas) {
int pos = getSelectionStart();
Layout layout = getLayout();
if (layout == null){
return canvas;
}
//Get where the cursor should be
float x = layout.getPrimaryHorizontal(pos);
//When there is no text, just off set it so that the whole cursor is drawn
if (x< mStroke/2){
x = mStroke/2
;
}
//Get the height of the edit text we will half this to center
//TODO this will only work for 1 line!!!!!!! Multi line edit text will need further adjustment
float height = canvas.getHeight();
//Get the text Height
float textHeight = getTextSize();
Paint p = new Paint();
p.setColor(mCursorColor);
p.setStrokeWidth(mStroke);
canvas.drawLine(x, height/2 - textHeight/2, x, height/2 +textHeight/2, p);
return canvas;
}
}
Usage is like this
feedbackText = (AutoCompleteEditTextStaticCursor) findViewById(R.id.input_text);
feedbackText.setCursorColor(getResources().getColor(R.color.cursor_color));
feedbackText.setCursorStroke(9);
Hope this helps someone.
Android EditText Blinking Cursor
To stop the cursor from blinking in an EditText
, simply use this line:
editText.setCursorVisible(false);
That's it.
How to prevent custom dialog from blinking cursor on first EditText inside of it
Use either XML attribute or Java function-
xml:
android:cursorVisible="false"
Java function:
setCursorVisible(false)
How to hide the cursor when typing on android EditText?
Try this:
android:cursorVisible="false"
How to remove focus from EditText when user is done editing?
You could use a xml attribute,
android:cursorVisible
or you can do it in code with this method.
setCursorVisible(boolean).
Related Topics
How to Use the Paid Version of My App as a "Key" to the Free Version
Remove Image from Cache in Glide Library
Cardview Layout_Width="Match_Parent" Does Not Match Parent Recyclerview Width
How to Get Screen Coordinates from Marker in Google Maps V2 Android
How to Fix Error: No Signature of Method: Build_Ap86Oam3Dut3Pxce3X49Rdtma.Android()
How to Apply Zoom, Drag and Rotation to an Image in Android
Fit Image in Imagebutton in Android
Adding Ripple Effect to Recyclerview Item
Get Certificate Fingerprint from Android App
Android Viewmodel Additional Arguments
Trying to Get the Display Size of an Image in an Imageview
Is Secure.Android_Id Unique for Each Device
Android Runonuithread Explanation