Я пытаюсь отобразить курсор в EditText, добавив
android:cursorVisible = "true"
в xml. Проблема в том, что версия приложения, написанная для полностью сенсорного устройства, которое использует softKeyboard, отображает курсор, но я разработал приложение также для устройств с физической клавиатурой, и когда я скрываю softkeyboard, курсор даже не виден.
Итак, вопрос в том, как сделать курсор видимым?
Например, вот мой XML-файл настраиваемого оповещения, и даже здесь курсор не отображается.
<RelativeLayout xmlns:tools = "http://schemas.android.com/tools"
android:background = "#ffffff"
xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent"
android:layout_height = "match_parent">
<TextView
android:id = "@+id/textView"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentStart = "true"
android:layout_alignParentTop = "true"
android:layout_marginBottom = "2dp"
android:layout_marginEnd = "10dp"
android:layout_marginLeft = "10dp"
android:layout_marginRight = "10dp"
android:layout_marginStart = "10dp"
android:layout_marginTop = "10dp"
android:text = "Site:"
tools:ignore = "HardcodedText" />
<EditText
android:cursorVisible = "true"
android:layout_margin = "10dp"
android:id = "@+id/site"
android:layout_width = "match_parent"
android:background = "#2323"
android:layout_height = "wrap_content"
android:layout_alignParentStart = "true"
android:layout_below = "@+id/textView"
android:ems = "10"
android:textSize = "24sp"
android:textColor = "#232323"
android:imeOptions = "actionDone"
android:inputType = "textUri"
tools:ignore = "LabelFor" />
<TextView
android:id = "@+id/textUser"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignStart = "@+id/textView"
android:layout_below = "@+id/site"
android:layout_marginTop = "5dp"
android:text = "User:"
tools:ignore = "HardcodedText" />
<EditText
android:cursorVisible = "true"
android:id = "@+id/editUser"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_alignParentStart = "true"
android:layout_below = "@+id/textUser"
android:layout_margin = "10dp"
android:background = "#2323"
android:ems = "10"
android:imeOptions = "actionDone"
android:inputType = "textNoSuggestions"
android:textColor = "#232323"
android:textSize = "24sp"
tools:ignore = "LabelFor" />
<TextView
android:id = "@+id/pswFtp"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignStart = "@+id/textView"
android:layout_below = "@+id/editUser"
android:layout_marginTop = "5dp"
android:text = "Password:"
tools:ignore = "HardcodedText" />
<EditText
android:cursorVisible = "true"
android:layout_margin = "10dp"
android:id = "@+id/editPswFtp"
android:layout_width = "match_parent"
android:background = "#2323"
android:layout_height = "wrap_content"
android:layout_alignParentStart = "true"
android:layout_below = "@+id/pswFtp"
android:ems = "10"
android:textSize = "24sp"
android:textColor = "#232323"
android:imeOptions = "actionDone"
android:inputType = "textNoSuggestions"
tools:ignore = "LabelFor" />
<Button
android:id = "@+id/save"
android:layout_below = "@+id/editPswFtp"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "#232323"
android:text = "SALVA"
tools:ignore = "HardcodedText" />
</RelativeLayout>
@NileshRathod добавил xml
ваш код работает нормально, пожалуйста, проверьте цвет вашей темы
@NileshRathod в моей Java, у меня эти параметры установлены на EditText editText.setInputType (InputType.TYPE_NULL); editText.setTextIsSelectable (true);
@NileshRathod, так что попробуйте без SoftKeyboard
Удалить editText.setInputType(InputType.TYPE_NULL);
@NileshRathod, я должен использовать его, так как у меня есть устройство с физической клавиатурой, без него откроется экранная клавиатура, которая мне не нужна
чем попытаться установить пользовательский курсор в вашем editText, например, stackoverflow.com/questions/7238450/set-edittext-cursor-colo r
@NileshRathod еще попробовал, и даже это не работает
android:textCursorDrawable = "@null"РЕШЕНО с помощью editText.setShowSoftInputOnFocus (false); вместо .setInputType
Вы можете просто создать свой собственный, который будет виден.
В res/drawable сделайте свой custom_cursor.xml
<?xml version = "1.0" encoding = "utf-8"?>
<shape xmlns:android = "http://schemas.android.com/apk/res/android" android:shape = "rectangle">
<size android:width = "2dp"/>
<solid android:color = "@color/colorPrimary"/>
</shape>
а затем добавьте его на свой EditText
android:textCursorDrawable = "@drawable/custom_cursor"
Вы можете выбрать свои собственные цвета и размер курсора.
Это не работает, поскольку я использую в своем java-файле editText.setInputType (InputType.TYPE_NULL); editText.setTextIsSelectable (true); так что курсор все равно не просматривается
@JohnKarry Почему вы используете editText.setInputType(InputType.TYPE_NULL);? потому что вы устанавливаете тип ввода НУЛЕВОЙ в своем Java-коде из-за того, что этот курсор не отображается. Если вы удалите / закомментируете эту строку, курсор должен начать отображаться.
@AnkitKumarSingh Я разработал приложение также для устройств с физической клавиатурой, и когда я скрываю программную клавиатуру, курсор даже не виден.
Решено с помощью
editText.setShowSoftInputOnFocus(false);
Вместо того
editText.setInputType(InputType.TYPE_NULL);
Поделитесь своим layout.xml с вопросом