EditTextカーソルの高さを変更したいのですが、方法を知っている人はいますか?
			
			13308 次
		
3 に答える
            27        
        
		
これに対する答えを見つけるために Android ソースを深く掘り下げる必要がありましたが、基本的には、カスタム シェイプのドローアブルでパディングを使用する必要があります。
注:サポートされているため、API 12 以降でのみ動作します。textCursorDrawable
正の 上部パディングを使用して、カーソルの上部を高く移動します
カーソルの下部を下に移動するためのユーザーの正の 下部パディング
lineSpacingMultiplierまたはを使用して行の高さを増やすと、カーソルがベースラインよりも低くなりすぎるため、通常は負の下部パディングを使用してカーソルを短くしますlineSpacingExtra。
例 cursor_red.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <size 
        android:width="2dip" />
    <solid
        android:color="@color/red" />
    <padding 
        android:top="2sp"
        android:bottom="-11sp" />
</shape>
これにより、2dip 幅の赤いカーソルが作成されます。
- トップで2sp高い(長い)
 - ボトムで11sp高い(短い)。
 
次に、編集テキストで次のように指定しますandroid:textCursorDrawable。
<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textCursorDrawable="@drawable/cursor_red" />
私が解決策を見つけたEditor.java内の関連するAndroidソースコード:
private void updateCursorPosition(int cursorIndex, int top, int bottom, float horizontal) {
    ...
    mCursorDrawable[cursorIndex].getPadding(mTempRect);
    ...
    mCursorDrawable[cursorIndex].setBounds(left, top - mTempRect.top, left + width,
            bottom + mTempRect.bottom);
}
    于 2013-03-06T00:01:19.530   に答える
    
    
            0        
        
		
editText スタイルをカスタム スタイルに変更する
<item name="android:editTextStyle">@style/myEditText</item>
次に、drawable を使用してカーソルを設定します。
<style name="myEditText" parent="@android:parentdetails">
<item name="android:textCursorDrawable">@android:drawable/my_cursor_drawable</item>
<item name="android:height">Height here e.g. 50sp</item> 
</style>
    于 2012-07-25T03:02:45.340   に答える