2014-04-01 124 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 –