[英]Unwanted margin in DropdownMenu in TextInputLayout
我的 TextInputLayout 中的邊距有問題。 下圖問題。 它變得非常難看,尤其是當列表中有 1 個元素時。
在下面發布我的代碼和樣式。 嘗試以編程方式擺脫這種填充,但也許這是樣式本身的一些問題。
<style name="AppTheme.TextInput.Dropdown" parent="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu">
<item name="materialThemeOverlay">
@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox.Dense
</item>
<item name="boxBackgroundColor">@color/colorBackground</item>
<item name="boxBackgroundMode">filled</item>
</style>
這就是我在代碼中的制作方式。 “視圖”是元素的容器
private fun addDictionaryField(layoutParams: ConstraintLayout.LayoutParams, formField: FormField): View {
val view = TextInputLayout(ContextThemeWrapper(this, R.style.AppTheme_TextInput_Dropdown))
view.layoutParams = layoutParams
val autoCompleteTextView = AutoCompleteTextView(ContextThemeWrapper(view.context, R.style.AppTheme_AutoCompleteEditText))
autoCompleteTextView.minEms = 4
autoCompleteTextView.maxEms = 6
autoCompleteTextView.isSingleLine = true
autoCompleteTextView.hint = formField.name
autoCompleteTextView.textSize = formField.fontSize?.toFloat() ?: 16F
autoCompleteTextView.dropDownHorizontalOffset = 0
autoCompleteTextView.dropDownWidth = LinearLayout.LayoutParams.MATCH_PARENT
//if (formField.fontColor != "auto" ) autoCompleteTextView.setTextColor(Color.parseColor(formField.fontColor))
//if (formField.backgroundColor != "auto" ) autoCompleteTextView.setBackgroundColor(Color.parseColor(formField.backgroundColor))
autoCompleteTextView.isEnabled = false
val structure = fillFormViewModel.getDictionaryStructure(formField.dictionaryStructure)
if (structure != null) {
if (structure.parentId == null) {
autoCompleteTextView.setAdapter(loadDictionaryFields(structure, null, null))
autoCompleteTextView.setOnItemClickListener { parent, _, position, _ ->
fillFormViewModel.dictionarySelectedElements[formField.id!!] = (parent.adapter.getItem(position) as DictionaryField).id!!
loadChildStructureFields(formField.dictionaryGroup, parent.adapter.getItem(position) as DictionaryField, null, null)
}
}
}
view.addView(autoCompleteTextView)
return view
}
任何人都有類似的問題? :)
必須更改樣式中的填充,因為默認情況下它有一些填充
<item name="android:padding">0dp</item>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.