android.support.design.widget.TextInputLayout 无法实例化

新手上路,请多包涵

我想在我的 android 应用程序中集成 android.support.design.widget.TextInputLayout 。我已将 jar 文件 android-support-design.jar 从 sdk 复制到我的应用程序 lib 文件夹。我在我的电子邮件 EditText 的 xml 文件中添加了以下代码,

  <!-- Email Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email" />
        </android.support.design.widget.TextInputLayout>

在我的 layout.xml 文件中添加此代码时,出现如下错误,

 Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be instantiated:
- android.support.design.widget.TextInputLayout (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.

我该如何解决这个问题…

原文由 SHIDHIN.T.S 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 522
2 个回答

如果您使用 AndroidStudio,则不应包含 android-support-design.jar。相反,在你的 build.gradle 中像下面这样写:

 dependencies {
    ...
    compile 'com.android.support:design:24.0.0'
    ...
}

编辑:如果这不起作用,您可能正在使用不同的版本。在 Windows 中,转到:

 [android-sdk]\extras\android\m2repository\com\android\support\design

在 Mac 上:

 sdk/extras/android/m2repository/com/android/support/design

该目录包含许多版本文件夹。在您的 build.gradle 上使用最新版本。

原文由 nshmura 发布,翻译遵循 CC BY-SA 3.0 许可协议

代替

android.support.design.widget.TextInputLayout

com.google.android.material.textfield.TextInputLayout

原文由 saigopi.me 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题