简体   繁体   English

如何从 AutoCompleteTextView 中删除大纲?

[英]How to remove the outline from AutoCompleteTextView?

I have a layout with several TextInputEditText fields nested in TextInputLayouts.我有一个嵌套在 TextInputLayouts 中的几个 TextInputEditText 字段的布局。 I also have one dropdown menu using AutoCompleteTextView, also nested in a TextInputLayout.我还有一个使用 AutoCompleteTextView 的下拉菜单,它也嵌套在 TextInputLayout 中。 I use a custom background drawable on the fields to create a rounded field.我在字段上使用自定义背景可绘制来创建圆形字段。 Unfortunately, I cannot for the life of me figure out how to get rid of the little outline around the AutoCompleteTextView .不幸的是,我一生都无法弄清楚如何摆脱AutoCompleteTextView 周围的小轮廓

With the TextInputEditText fields, I can eliminate the outlines by setting the background on it.使用 TextInputEditText 字段,我可以通过设置背景来消除轮廓。 Doing this on the AutoCompleteTextView does nothing, and I have to set it on the parent TextInputLayout to see the background.在 AutoCompleteTextView 上执行此操作无济于事,我必须在父 TextInputLayout 上设置它才能看到背景。 But yet, the outline remains.但是,轮廓仍然存在。

I believe this has something to do with material design (and its styles?) because when you press on the field, the outline turns orange, which is the primary color in our app's theme as set in the styles.xml.我相信这与材料设计(及其样式?)有关,因为当您按下该字段时,轮廓变为橙色,这是我们在 styles.xml 中设置的应用程序主题的主要颜色。

Here is a relevant snippet of the XML layout in question.这是相关 XML 布局的相关片段。 For comparison, the first part is the city field, and the second is the state field:为了比较,第一部分是city字段,第二部分是state字段:

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/input_city"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:visibility="@{viewModel.addDevice.isFinishedWithSettings ? View.INVISIBLE : View.VISIBLE}"
        app:endIconMode="clear_text"
        app:hintEnabled="false"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/input_apartment">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/input_city_edit_text"
            style="@style/AppFont500.DarkGrey.EditTextHint"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingStart="25dp"
            android:paddingEnd="25dp"
            android:paddingLeft="25dp"
            android:paddingRight="25dp"
            android:visibility="@{viewModel.addDevice.isFinishedWithSettings ? View.INVISIBLE : View.VISIBLE}"
            android:imeOptions="actionDone"
            android:inputType="number"
            android:text="@={viewModel.addDevice.city}"
            android:hint="@string/hint_city"
            android:background="@drawable/rounded_edittext_states"
            />

    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/input_state"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:visibility="@{viewModel.addDevice.isFinishedWithSettings ? View.INVISIBLE : View.VISIBLE}"
        app:endIconMode="dropdown_menu"
        app:hintEnabled="false"
        app:layout_constraintEnd_toStartOf="@id/input_zip_code"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/input_city"
        android:background="@drawable/rounded_edittext_states"
        >

        <AutoCompleteTextView
            android:id="@+id/input_state_edit_text"
            style="@style/AppFont500.DarkGrey.EditTextHint"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingStart="25dp"
            android:paddingEnd="25dp"
            android:paddingLeft="25dp"
            android:paddingRight="25dp"
            android:layout_marginEnd="4dp"
            android:visibility="@{viewModel.addDevice.isFinishedWithSettings ? View.INVISIBLE : View.VISIBLE}"
            android:imeOptions="actionDone"
            android:inputType="none"
            android:text="@={viewModel.addDevice.state}"
            android:hint="@string/hint_state"
            />

    </com.google.android.material.textfield.TextInputLayout>

I believe the key here involves styles and themes.我相信这里的关键在于风格和主题。 Here are the custom styles and theme used within this snippet:以下是此代码段中使用的自定义样式和主题:

    <style name="AppMaterialTheme" parent="@style/Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/primaryOrange</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
    <style name="AppFont500">
        <item name="fontFamily">@font/poppins_medium_500</item>
    </style>    

    <style name="AppFont500.DarkGrey">
        <item name="android:textColor">@color/secondaryDarkGrey</item>
    </style>    

    <style name="AppFont500.DarkGrey.EditTextHint">
        <item name="android:textSize">16sp</item>
    </style>

The background comes from this selector.背景来自这个选择器。 It previously had more items, but right now just has one:它以前有更多的项目,但现在只有一个:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item
        android:state_enabled="true"
        android:drawable="@drawable/rounded_edittext" />
    </selector>

And the drawable:和可绘制的:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp">

        <solid android:color="#FFFFFF" />
    <corners
    android:radius="30dp" />
    </shape>

Mainly, what I have seen in questions related to outlines around edit texts is to either edit the stroke or boxStroke.主要是,我在与编辑文本周围的轮廓相关的问题中看到的是编辑笔画或 boxStroke。 I tried both and set them to an invisible value, but it does not change the stroke at all.我尝试了两者并将它们设置为一个不可见的值,但它根本不会改变笔画。

Here is how you remove this outline.这是删除此轮廓的方法。

In your TextInputLayout XML code add the following snippet:在您的TextInputLayout XML 代码中添加以下代码段:

app:boxStrokeWidth="0dp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM