2014-04-01 38 views
0

我有以下XML:显示我EDITTEXT搜索视图光标

<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> 

软键盘打开的那一刻活动上。

我该如何强制文本光标出现并闪烁?

时下即使在用户点击这个editText后它也不会出现。

我已经加入<requestFocus />,但它并没有帮助

这是我的代码:

@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); 
    } 
} 
+0

尝试'android:textCursorDrawable =“@ null”' – InnocentKiller

+0

你试过这个以编程方式吗?我有这样的成功:'EditText输入= FindViewById (Resource.Id.searchBox); input.RequestFocus();' – Byron

+0

尝试过,但没有工作 –

回答

0
 android:textCursorDrawable="@drawable/my_cursor" 
0

你可以试试,如果要查看EDITTEXT光标,只需使用

android:textCursorDrawable="@null" 
android:textColor="@color/someColor" 

PS :如果要更改光标的颜色,可以更改颜色,但颜色是可选的,但是是incase。

+0

android:textCursorDrawable =“@ drawable/my_cursor” –

-1

尝试 searchBox.setSelection(0);

+0

requestFocus是需要的吗? –

+0

是的,保存在那里。 – lambda

+0

没有帮助。请看我的updte –