[英]Unwanted margin in DropdownMenu in TextInputLayout
im having a problem with margin in my TextInputLayout.我的 TextInputLayout 中的边距有问题。 Below picture of problem.下图问题。 It gets very ugly especially when there is 1 element in list.它变得非常难看,尤其是当列表中有 1 个元素时。
Posting my code and style below.在下面发布我的代码和样式。 Tried getting rid of this padding programmaticaly but maybe thats some issue with style itself.尝试以编程方式摆脱这种填充,但也许这是样式本身的一些问题。
<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>
And this is how i make it in code.这就是我在代码中的制作方式。 "view" is the container for elements “视图”是元素的容器
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
}
This is how i like it to look (except for this is not dropdown choice menu)这就是我喜欢它的外观(除了这不是下拉选择菜单)
Anyone had simmilar problem by any chance ?任何人都有类似的问题? :) :)
Had to change padding in style becouse it had some padding by default必须更改样式中的填充,因为默认情况下它有一些填充
< item name= "android:padding">0dp< /item > <item name="android:padding">0dp</item>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.