2017-01-26 4 views
0

私は、このような材料分野imageを持っていますが、私はあなたがJavaを使用して目的の位置にカーソルを移動することができますヒント重要なedittextのヒントを動かさずにカーソルを移動するには?

<android.support.design.widget.TextInputLayout 
     android:id="@+id/layout_password" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textColorHint="@color/colorTextGray" 
     app:passwordToggleEnabled = "true" 
     app:passwordToggleTint="@color/color_ic_visibility" 
     app:passwordToggleDrawable="@drawable/ic_visibility"> 
     <EditText 
      android:id="@+id/password" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="45dp" 
      android:backgroundTint="@color/colorNotSelected" 
      android:hint="Пароль" 
      android:inputType="textPassword" 
      android:textColor="@color/colorTextGray" 
      android:fontFamily="sans-serif" /> 
    </android.support.design.widget.TextInputLayout> 
+0

はあなたがアンドロイドを追加しようとしたことがありますか? –

+0

うん。しかしその後、浮動ラベルも動きます。私はカーソルだけを交換する必要があります – Antony

答えて

1

を交換することなく、このようなimageカーソルを交換する必要があります。では、あなたのActivityあなたは、この方法を試みることができる:

EditText editText = (EditText)findViewById(R.id.password); 
editText.setSelection(//position); 

https://developer.android.com/reference/android/text/Selection.html#setSelection(android.text.Spannable, int)

EditTextがコンテンツを必要とするためしかし、これは、ヒントだけを使用して動作しません。あなたはこのコードを使用して独自のヒントを作成することによってこの問題を回避することができます

EditText editText = (EditText)findViewById(R.id.password); 
editText.setText("Пароль"); 
editText.setSelection(3); // for example 3 

参考:EDITTEXTにpaddingStart:How to set focus to the text after the hint in EditText?

+0

私は空のedittextを持っています。私は開始カーソルの位置をオーバーライドする必要があります。パディングを追加した後、フローティングラベルも動いています。 – Antony

+0

ヒントだけを使って点を付けることはできません。あなたは更新された答えを使用してこれを回避することができます。 –

+0

番号。私はテキストを入力せずに移動する必要があります。テキストは40dpの最初から右に始まります – Antony

関連する問題