Android select and highlight text in edittext -
i app has edittext or textview can selected upon click , highlight selected text. how can that? tried overriding onclick method on edittext seems not working.
here's i've tried far:
etx.setonlongclicklistener(new onlongclicklistener() { @override public boolean onlongclick(view v) { int startselection = etx.getselectionstart(); int endselection = etx.getselectionend(); //string selectedtext = etx.gettext().tostring().substring(startselection, endselection); spannable spannable=new spannablestring(etx.gettext().tostring()); spannable.setspan(new foregroundcolorspan(color.blue), startselection, endselection, 0); etx.settext(spannable); return true; } }); <edittext android:id="@+id/tvordinancetitle" android:layout_width="wrap_content" android:textcolor="@android:color/black" android:cursorvisible="false" android:layout_height="wrap_content" android:background="#00000000" > </edittext>
but it's not working. workaround? gladly appreciate help. thanks.
you can better use textview background set , edittext ,
since using on click listener on edittext not practice because shows keyboard when click on it, still if want use edittext same purpose , can refer this: android edittext onclicklistener
Comments
Post a Comment