TextInputLayout > AutompleteTextView(下拉样式)样式问题

问题描述 投票:0回答:1

嗨,我花了 2 天尝试设计一个充当下拉菜单的 AutocompleteTextView 的样式。

我最好的成绩是下一个:

Problem image

我的目标:当聚焦时,蓝色轮廓包围所有组件。

我的布局:

<com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/vaultsDropDown"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    style="@style/til_dropDown"
                    android:layout_marginLeft="10dp"
                    >

                    <AutoCompleteTextView
                        android:layout_width="match_parent"
                        android:layout_height="50dp"
                        android:inputType="none"
                        android:paddingLeft="10dp"
                        android:text="Hola"

                         />

我的风格:

<style name="til_dropDown" parent="Widget.Material3.TextInputLayout.FilledBox.ExposedDropdownMenu">
    <item name="android:textColorHint">#666666</item>
    <item name="boxStrokeWidth">0dp</item>
    <item name="boxStrokeWidthFocused">0dp</item>
    <item name="materialThemeOverlay">@style/til_dropdown_materialThemOverlay</item>
</style>

<style name="til_dropdown_materialThemOverlay" >
    <item name="backgroundTint">@android:color/transparent</item>
    <item name="android:background">@drawable/textinputlayout_edittext</item>
    <item name="android:textSize">15sp</item>
    <item name="android:textColor">#112531</item>
</style>

蓝色聚焦的背景状态:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true">
        <shape android:shape="rectangle">
            <solid android:color="#F5F5F5"/>
            <stroke android:width="2dp" android:color="@color/colorPrimary"/>
            <corners android:radius="3dp"/>
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#F5F5F5"/>
            <stroke android:width="0dp" android:color="#F5F5F5"/>
            <corners android:radius="3dp"/>
        </shape>
    </item>
</selector>
android styles autocompletetextview textinputlayout
1个回答
0
投票

所以解决方案是使其样式为轮廓样式而不是填充样式:

<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/vDropDown"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                style="@style/til_dropDown"
                android:layout_marginLeft="10dp"
                >

                <AutoCompleteTextView
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:inputType="none"
                    android:paddingLeft="10dp"
                     />
            </com.google.android.material.textfield.TextInputLayout>

关于款式:

<style name="til_dropDown" parent="Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
        <item name="android:textColorHint">#666666</item>
        <item name="boxCornerRadiusBottomEnd">3dp</item>
        <item name="boxCornerRadiusTopEnd">3dp</item>
        <item name="boxCornerRadiusBottomStart">3dp</item>
        <item name="boxCornerRadiusTopStart">3dp</item>
        <item name="materialThemeOverlay">@style/til_dropdown_materialThemOverlay</item>
        <item name="android:background">@drawable/textinputlayout_edittext</item>
    </style>
© www.soinside.com 2019 - 2024. All rights reserved.