使用新的 TextInputLayout 进行 EditText 的渲染问题

2023-12-26

我正在尝试设置新的 support.desing 库,为旧的 Android 版本提供一些棒棒糖视觉效果。

在本例中,我尝试为 edittext 添加浮动标签,这是通过 widget.TextInputLayout 完成的:

为此,我遵循了谷歌提供的一些指示:

  • 我已经下载了最后一个支持库(22.2.0)并包含在 gradle 文件中。

    编译'com.android.support:design:22.2.0'

  • 我以这种方式在 xml 中添加了 TextInputLayout:

<android.support.design.widget.TextInputLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_marginLeft="20dp">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="12"
        android:hint="hint"
        android:inputType="number"
        android:id="@+id/edt" />
</android.support.design.widget.TextInputLayout>

但 Android Studio 在布局预览中显示了这一点:

Rendering failed with a known bug. Please try a rebuild.  
The following classes could not be instantiated:
- android.support.design.widget.TextInputLayout (Open Class, Show Exception, Clear Cache)

Exception Details 
java.lang.NoSuchFieldError: TextAppearance

这是我正在使用的样式:

<style name="MaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/md_red_500</item>
    <item name="colorPrimaryDark">@color/darkPrimaryColor</item>
    <item name="colorAccent">@color/md_green_500</item>
    <item name="android:textColorPrimary">@color/md_grey_900</item>
    <item name="android:textColorSecondary">@color/md_grey_600</item>
</style>

EDIT-


解决了。必须添加这个:

<android.support.design.widget.TextInputLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:layout_marginLeft="20dp"
            app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">

这就是:

<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/accentColor</item>
</style>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用新的 TextInputLayout 进行 EditText 的渲染问题 的相关文章

随机推荐