Android OutlinedBox 样式在 TextInputLayout 中不起作用

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

我搜索并尝试了很多解决方案,但还是不行。
(仍然显示“FilledBox”样式)
我的代码有什么问题?

input_layout.xml

<com.google.android.material.textfield.TextInputLayout
        android:theme="@style/Theme.MaterialComponents.Light.NoActionBar" 
        android:id="@+id/text_input_layout"
        tyle="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        ...
        >
<com.google.android.material.textfield.TextInputEditText
            android:id="@+id/text_input_edit_text"
        ...
 />
    </com.google.android.material.textfield.TextInputLayout>

styles.xml

    <style name="AppBaseTheme" parent="android:Theme.MaterialComponents.Light"/>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="textInputStyle">@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item>
    </style>

android android-layout material-components-android
1个回答
0
投票

你可以尝试这个代码,它对我有用

<com.google.android.material.textfield.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:boxStrokeColor="@color/bg_blue_tint"
    app:boxStrokeWidth="2dp"
    app:boxStrokeWidthFocused="2dp"
    app:endIconDrawable="@drawable/ic_email"
    app:endIconMode="custom"
    app:hintEnabled="false"
    android:hint="Email"
    android:layout_marginHorizontal="20dp"
    android:layout_marginBottom="15dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="@string/email"
        android:maxLines="1"
        android:imeOptions="actionNext"
        android:inputType="textEmailAddress"
        android:textColorHint="@color/hint_color" />
</com.google.android.material.textfield.TextInputLayout>

当聚焦时,这段代码看起来像这样

© www.soinside.com 2019 - 2024. All rights reserved.