在android中设置AutoCompleteTextView分隔符高度没有效果
这是我的AutoCompleteTextView在android中设置AutoCompleteTextView分隔符高度没有效果,android,android-layout,autocompletetextview,Android,Android Layout,Autocompletetextview,这是我的AutoCompleteTextView <AutoCompleteTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:dividerHeight="4dp" android:gravity="center" android:inputType="textCapWords|te
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="4dp"
android:gravity="center"
android:inputType="textCapWords|textAutoCorrect"
android:textColor="@color/font_autocomplete"
android:textSize="18sp" />
有人知道为什么设置android:dividerHeight没有效果吗?自动完成文本视图是一个复合视图-它既有一个
EditText
组件,也有一个浮动的下拉列表
组件。EditText
组件的样式很简单,但是下拉列表
很困难,因为它是AutoCompleteTextView
本身属性和主题中通过android:dropDownListViewStyle
设置的样式的混合体
如果要更改分隔符,必须创建一个主题并将其指向一个样式,这不是一个显而易见的解决方案:
<style name="MyTheme">
<item name="android:dropDownListViewStyle">@style/DropDownListViewStyle</item>
</style>
<style name="DropDownListViewStyle">
<item name="android:dividerHeight">4dp</item>
</style>
@样式/下拉列表视图样式
4dp
但是,请注意,这些样式更改将应用于整个应用程序。因此,如果您的UI中有其他
下拉列表组件,它们可能也会受到影响。AutoCompleteTextView是一个复合视图-它既有编辑文本组件,也有浮动下拉列表组件。EditText
组件的样式很简单,但是下拉列表
很困难,因为它是AutoCompleteTextView
本身属性和主题中通过android:dropDownListViewStyle
设置的样式的混合体
如果要更改分隔符,必须创建一个主题并将其指向一个样式,这不是一个显而易见的解决方案:
<style name="MyTheme">
<item name="android:dropDownListViewStyle">@style/DropDownListViewStyle</item>
</style>
<style name="DropDownListViewStyle">
<item name="android:dividerHeight">4dp</item>
</style>
@样式/下拉列表视图样式
4dp
但是,请注意,这些样式更改将应用于整个应用程序。因此,如果您的UI中有其他下拉列表
组件,它们可能也会受到影响。Autocompletetextview下拉列表自定义项分隔符可以使用以下项布局和可绘制项来实现。
供参考
自定义布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
style="?android:attr/dropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="6dp"
android:enabled="false"
android:background="@drawable/divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>
可定制绘图
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:tint="#42a5f5"
android:shape="rectangle">
<corners
android:radius="4dp"/>
<size
android:height="6dp" />
<solid android:color="#42a5f5" />
</shape>
Autocompletetextview下拉菜单自定义项目分隔符可以使用下面的项目布局和可绘图功能实现。
供参考
自定义布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
style="?android:attr/dropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="6dp"
android:enabled="false"
android:background="@drawable/divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>
可定制绘图
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:tint="#42a5f5"
android:shape="rectangle">
<corners
android:radius="4dp"/>
<size
android:height="6dp" />
<solid android:color="#42a5f5" />
</shape>
谢谢你的回答(+1)。有没有一种方法可以不影响整个应用程序,不管它多么复杂?你可以将它应用到这样的活动中:谢谢你的回答(+1)。有没有一种方法可以不影响整个应用程序,无论它多么复杂?您可以将其应用于以下活动: