TextInputLayout

问题描述

我正在尝试使用Outline Boarder创建TextInputLayout。但是,无论何时我使用以下样式,它都会使应用程序发生故障(崩溃)。
在发布之前,我已经尝试了stackoverflow内外列出的所有解决方案,但是到目前为止,仍没有解决该问题的方法。

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"

当前布局

<ScrollView...

    <LinearLayout
      android: layout_width = "200dp"
      android: layout_height = "wrap_content"
      android: orientation = "vertical"
      android: layout_marginTop = "2dp" >

    <com.google.android.material.textfield.TextInputLayout
       android: id = "@+id/outlinedTextField"
       android: layout_width = "match_parent"
       android: layout_height = "wrap_content"
       android: hint = "@string/label"
       style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
       app: boxStrokeWidthFocused = "2dp"
       app: boxStrokeColor = "@color/border_primary" >

    <com.google.android.material.textfield.TextInputEditText
       android: layout_width = "match_parent"
       android: layout_height = "wrap_content" />
    
  </LinearLayout>

</ScrollView>

完整版式:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".user.userprofile.UserProfileFragment">
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <include layout="@layout/user_profile_header"/>
    
            <LinearLayout
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/outlinedTextField"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android: hint = "@string/label"
                    app:hintTextColor="@color/text_primary"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                    app:boxStrokeWidthFocused="2dp"
                    app:hintTextColor="@color/text_primary"
                    app:boxStrokeColor="@color/border_primary">
    
                    <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
    
            </LinearLayout>
    
        </LinearLayout>
    
    </ScrollView>

更多信息:添加stylehint失去了焦点。边框也不会出现。

解决方法

您需要检查几件事:

  1. 确保您的resultAppTheme(或后代)。

因此,您的style.xml应该类似于

Theme.MaterialComponents
  1. 您将材料成分库添加到模块gradle文件中

<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.MaterialComponents"> <!-- rest of your style items--> </style> </resources>

,

TextInputLayout不是自闭标签。 编辑您的代码,并将TextInputEditText放在TextInputLayout中。

<com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/outlinedTextField"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android: hint = "@string/label"
                    app:hintTextColor="@color/text_primary"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                    app:boxStrokeWidthFocused="2dp"
                    app:hintTextColor="@color/text_primary"
                    app:boxStrokeColor="@color/border_primary">
    
                    <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
    </com.google.android.material.textfield.TextInputLayout>

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...