我不明白我做錯了什么。我只想顯示下拉選單。結果如下圖所示:我可以在上面編輯并顯示鍵盤。我錯過了什么?
方面(未啟用指標):

結果:

XML 布局
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/gender_container"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="10dp"
android:hint="Gender"
app:layout_constraintTop_toBottomOf="@ id/year_of_bird_container">
<AutoCompleteTextView
android:id="@ id/gender_spinner"
android:layout_width="match_parent"
android:inputType="none"
android:layout_height="match_parent"/>
</com.google.android.material.textfield.TextInputLayout>
從片段
private fun setAdapter() {
val genderList = mutableListOf(
Gender.MALE.toString(),
Gender.FEMALE.toString(),
Gender.OTHER.toString(),
Gender.PREFER_NOT_TO_SAY.toString()
)
val adapter = ArrayAdapter(
requireContext(), R.layout.simple_spinner_dropdown_item, genderList
)
binding.genderSpinner.setAdapter(adapter)
}
uj5u.com熱心網友回復:
我建議您使用如下所示的微調器。AutoCompleteTextView 實際上不是微調器。
<androidx.appcompat.widget.AppCompatSpinner
android:id="@ id/spinner"
style="@style/AddressSpinnerTheme"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="5dp"
app:entries="@{viewModel.uiState.value.spinnerItemList}"
app:newValue="@{viewModel.uiState.value.spinnerSelectedItem}"
app:onItemSelected="@{listener}" />
uj5u.com熱心網友回復:
我在之前的專案中使用了 AutoCompleteTextView,用法是一樣的。但是為了確保我剛剛創建了新專案并添加了您的代碼,它也可以正常作業。
也許將 android:imeOptions="actionDone" 添加到以前的 EditText 可能會解決它,因為它可以使用鍵盤,當你完成它時,如果它不是 actionDone,鍵盤會留給下一個組件。
除此之外,請檢查影響此的其他代碼部分,例如 onFocus 或 onClick 事件。如果不是關于他們,我建議您創建新專案并逐步重試以找出導致此問題的原因。
uj5u.com熱心網友回復:
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/gender_container"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="10dp"
android:hint="Gender"
app:layout_constraintTop_toBottomOf="@ id/year_of_bird_container">
<AutoCompleteTextView
android:id="@ id/gender_spinner"
android:layout_width="match_parent"
android:inputType="none"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:layout_height="match_parent"/>
</com.google.android.material.textfield.TextInputLayout>
uj5u.com熱心網友回復:
如果您不想顯示Softkeyboad但保留cursor/ ,可以試試這個caret。把它放在你的活動中
window.setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
cursor/caret顯示沒有活動的螢屏截圖SoftKeyboard

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/518420.html
