首页 > 解决方案 > 当我在样式中设置 OutlinedBox 时,TextInputLayout 不起作用

问题描述

implementation 'com.google.android.material:material:1.1.0' 在它不起作用之后处理布局添加的依赖项

   <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="20dp"
                android:layout_below="@+id/textView"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

        <EditText
                android:id="@+id/editTextCode"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawablePadding="10dp"
                android:inputType="phone"
                android:maxLength="6"
                android:paddingStart="3dp"
                android:drawableLeft="@android:drawable/stat_sys_phone_call"
                android:gravity="start"
                />
    </com.google.android.material.textfield.TextInputLayout>`

标签: androidandroid-studioandroid-layoutandroid-textinputlayoutmaterial-components-android

解决方案


使用 EditText 的 TextInputEditText。检查下面的代码

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayoutName"          
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/textInputLayoutEditTextName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Name"
                    android:inputType="text"
                    android:text="Data" />

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

推荐阅读