2014-05-09 62 views
2

是否可以讓EditText的光標水平放置而不垂直?我想有像下面的圖片:水平編輯文本的光標

horizontal cursor

我看過一些主題是人與機器人玩:textCursorDrawable,但我需要它的風格也爲Android 3.0 <。有任何想法嗎?

編輯: 我加入的EditText的XML:

<EditText 
    android:id="@+id/edittext1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:cursorVisible="true" 
    android:ems="10" 
    android:hint="@string/id" 
    android:inputType="text" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:textCursorDrawable="@drawable/custom_bottom_cursor" /> 
+0

使用android:textCursorDrawable =「@ drawable/your_cursor_drawable」 – Sripathi

回答

2

1)創建一個遊標繪製。

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <size 
     android:width="20dp" 
     android:height="1dp" /> 
    <solid 
     android:color="#000000" /> 
    <padding 
     android:top="-20sp" 
     android:bottom="1sp" /> 


</shape> 

或者你喜歡。
2)android:textCursorDrawable="@drawable/cursor_drawable"
但這僅適用於蜂窩或更高...
Success

+0

@iyoon也許我做錯了什麼,但在新設備上,我沒有看到光標和設備與Android 2.3.6我看到一樣的光標一直。我已將包含EditText的活動的佈局放入文件夾layout-v11中,並將drawable-xhdpi文件夾中的自定義drawable放入。我還添加了textCursorDrawable和cursorVisible。我究竟做錯了什麼? – AlvaroSantisteban

+0

自定義drawable應放置在'drawable'文件夾中,不指定dpi。 – jyoon

+0

仍然沒有運氣。我更新了我的問題,以防萬一:P – AlvaroSantisteban

1

我一直在尋找類似的東西,但我沒有找到一個解決辦法:(只有一個想法,我已經找到了設置cursorVisible假

editText.setCursorVisible(false); 

然後動態追加炭_結束的EditText,一組閃爍動畫結束的

Animation anim = new AlphaAnimation(0.0f, 1.0f); 
anim.setDuration(50); //You can manage the time of the blink with this parameter 
anim.setStartOffset(20); 
anim.setRepeatMode(Animation.REVERSE); 
anim.setRepeatCount(Animation.INFINITE); 
lastChar.startAnimation(anim); 
+0

謝謝!如果我無法讓jyoon的方法奏效,我會使用你的解決方法:) – AlvaroSantisteban

+0

沒問題,如果jyoon的答案有效,我也會使用它:-) –

+0

但問題是,@AlvaroSantisteban能夠使它工作嗎? :D –

相關問題