Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在不移动材质文本中的提示的情况下移动光标?_Android_Android Edittext_Cursor Position - Fatal编程技术网

Android 如何在不移动材质文本中的提示的情况下移动光标?

Android 如何在不移动材质文本中的提示的情况下移动光标?,android,android-edittext,cursor-position,Android,Android Edittext,Cursor Position,我有这样一个材质字段,但我需要像这样替换光标而不替换提示 <android.support.design.widget.TextInputLayout android:id="@+id/layout_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColorHint="@color/co

我有这样一个材质字段,但我需要像这样替换光标而不替换提示

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

您可以使用Java将光标移动到所需位置。在您的
活动中
可以尝试以下方法:

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

但是,仅使用提示不起作用,因为
EditText
需要内容。您可以通过使用以下代码创建自己的提示来解决此问题:

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

参考:

您可以使用Java将光标移动到所需位置。在您的
活动中
可以尝试以下方法:

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

但是,仅使用提示不起作用,因为
EditText
需要内容。您可以通过使用以下代码创建自己的提示来解决此问题:

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

参考资料:

您是否尝试将android:paddingStart添加到editText?是的。但在那之后,浮动标签也会移动。我只需要更换光标。你有没有试过将android:paddingStart添加到editText?是的。但在那之后,浮动标签也会移动。我只需要替换cursori有空的edittext。我需要覆盖起始光标位置。添加填充后,浮动标签也在移动。您不能仅使用提示来点那个。您可以使用更新的答案解决此问题。否。我需要在不输入任何文本的情况下移动。文本应该从40dp的开头开始,然后使用android:paddingLeft=“10dp”,但在这之后,浮动标签也会移动。我的编辑文本为空。我需要覆盖起始光标位置。添加填充后,浮动标签也在移动。您不能仅使用提示来点那个。您可以使用更新的答案解决此问题。否。我需要在不输入任何文本的情况下移动。文本应该从40dp的开头开始,然后使用android:paddingLeft=“10dp”,但之后浮动标签也会移动。