[英]How to remove the underline under TextInputLayout in Android Material Design?
[英]How to remove underline from dropdown menu material design in android
我似乎无法摆脱根据我的 android UI 中的材料设计指南完成的Exposed Dropdown Menu中的黑色下划线。
下拉列表如下所示:
我曾尝试将背景设置为空、透明或自定义形状。 app:boxBackgroundMode="none"
也不起作用。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/spinner_age"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_rounded_button"
android:hint="Age">
<AutoCompleteTextView
android:id="@+id/age_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
理想情况下,下拉菜单看起来像一个没有下划线的按钮。 我该如何摆脱它?
请更改您的这一行
android:background="@android:color/transparent"
和
android:background="#00000000"
使背景 = 空
<AutoCompleteTextView
android:id="@+id/age_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"/>
只需添加此行即可删除下划线
android:inputType="textNoSuggestions"
只需使用标准样式@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu
和
您不需要使用自定义背景形状,您只需使用app:boxCornerRadius*
属性来定义圆形。
就像是:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
app:boxCornerRadiusBottomEnd="32dp"
app:boxCornerRadiusTopEnd="32dp"
app:boxCornerRadiusBottomStart="32dp"
app:boxCornerRadiusTopStart="32dp"
app:boxStrokeColor="@color/myselector"
...>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
/>
</com.google.android.material.textfield.TextInputLayout>
要更改组件下线条的颜色,您必须更改app:boxStrokeColor
属性。 只需根据您的喜好自定义选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="0" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0" android:color="?attr/colorOnSurface"/>
</selector>
这是结果:
注意:当使用带有
EditText
子@null
而不是TextInputEditText
的填充文本字段时,请确保将EditText
的android:background
为@null
。 这允许TextInputLayout
在EditText
上设置填充背景。
选择:
在新版本 1.1.0 中,您还可以使用shapeAppearanceOverlay
属性来自定义组件的形状。
只需使用:
<com.google.android.material.textfield.TextInputLayout
style="@style/MyFilledBox_ExposedDropdownMenu
...>
<AutoCompleteTextView
android:background="@null"
... />
</com.google.android.material.textfield.TextInputLayout>
和这种风格:
<!-- Rounded -->
<style name="MyFilledBox_ExposedDropdownMenu" parent="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu">
<item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded</item>
<item name="boxStrokeColor">@color/myselector</item>
</style>
<style name="ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">32dp</item>
</style>
设置boxStrokeWidth = 0dp
可以解决它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.