Android EditText - Stop cursor blinking, want a solid cursor -


i want able see cursor time. no blinking, , no hiding.

i extend edittext , rendering graphic , of-setting text written pain , need redundant work recognise user taps / cursor moves.

to clear

edittext.setcursorvisible(false); 

is not answer looking for.

possibly set in xml drawable file?

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >     <size android:width="1dp" />     <stroke android:color="@android:color/black"/>     <solid android:color="@android:color/black"/> </shape> 

but seems unlikely.

here edittext

 <autocompletetextview         android:id="@+id/input_text"         android:layout_width="fill_parent"         android:layout_height="0dp"         android:textsize="7mm"         android:drawableright="@drawable/clear_tran"         android:drawableend="@drawable/clear_tran"         android:background="@android:color/transparent"          android:cursorvisible="true"         android:textcursordrawable="@drawable/cursor"          android:text=""         android:autolink="none"        android:textappearance="@android:style/textappearance.holo.medium"         android:clickable="true"         android:inputtype="text|textnosuggestions"         android:layout_weight="1"         android:textstyle="normal"         android:singleline="true"         android:textisselectable="false"         android:layout_marginleft="2mm"         android:layout_marginright="2mm"         android:layout_marginbottom="1mm"/> 

any suggestions meta-mind? googles returning how hide cursor.

i keep investigating , return results.

okay, seems api not allow static cursor. created own extension of autocompletetextview renders cursor never blinks. (you can use same code extend noemal edittext or other derivative)

bewarned if want have multiline edit text height parameters need work. have assumed 1 line , centered height on text box.

    public class autocompleteedittextstaticcursor extends autocompletetextview {              private int mcursorcolor = color.black; //cursor defaults black             private       int mstroke = 5; //default stroke 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 cursor color          * must have static int reference.          * if wish use resource use following method          * int color = getresources().getcolor(r.color.yourcolor);          *          * default value color.black          * @param color          */         public void setcursorcolor(int color){ //cursor defaults black             mcursorcolor = color;         }          /**          * set cursor stroke width          *          * default value 5          * @param stroke          */         public void setcursorstroke(int stroke){             mstroke = stroke;         }          @override         protected void ondraw(canvas canvas) {              //take opportunity draw our cursor             canvas = drawcursor(canvas);              super.ondraw(canvas);         }          /**          * draw cursor simple line,           * possible render drawable if wanted rounded corners           * or additional control on cursor           *           * @param canvas          * @return          */         private canvas drawcursor(canvas canvas) {              int pos = getselectionstart();             layout layout = getlayout();              if (layout == null){                 return canvas;                }              //get cursor should             float x = layout.getprimaryhorizontal(pos);       //when there no text, off set whole cursor drawn             if (x< mstroke/2){                 x = mstroke/2  ;         }              //get height of edit text half center             //todo work 1 line!!!!!!! multi line edit text need further adjustment             float height = canvas.getheight();              //get 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 this

 feedbacktext = (autocompleteedittextstaticcursor) findviewbyid(r.id.input_text);     feedbacktext.setcursorcolor(getresources().getcolor(r.color.cursor_color));     feedbacktext.setcursorstroke(9); 

hope helps someone.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -