android:textCursorDrawable="@drawable/my_cursor"
showing the cursor in my editText search view
Вопрос
I have the following xml:
<LinearLayout
android:id="@+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/theTitleBar"
android:orientation="horizontal" >
<EditText
android:id="@+id/searchBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="1dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="@drawable/text_area_search"
android:imeOptions="actionSearch"
android:textSize="14dp" >
<requestFocus />
</EditText>
<ImageButton
android:id="@+id/speechRecognition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="7dp"
android:layout_weight="0"
android:background="@drawable/recording_bt_crop_idle"
android:onClick="speechRecognitionClicked"
android:visibility="visible" />
</LinearLayout>
the soft-keyboard is open the moment the activity is on.
how can i force the text cursor appear and blink?
nowadays it doesn't appear even after the user clicks in this editText.
I have added <requestFocus />
but it didn't help
this is my code:
@Override
public void onResume() {
super.onResume();
if (type==AddressItem.FAVORITE_ITEM_EMPTY) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
searchBox.requestFocus();
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(searchBox, InputMethodManager.SHOW_FORCED);
}
}, 100);
}
}
Решение 2
Другие советы
You can try, To show cursor in editText, just use
android:textCursorDrawable="@null"
android:textColor="@color/someColor"
PS: Color is an optional but incase if you want to change color of cursor you can change it.
Try searchBox.setSelection(0);
Не связан с StackOverflow