![](/img/trans.png)
[英]Android java android.support.design.widget.TextInputLayout with clear button
[英]android.support.design.widget.TextInputLayout could not be instantiated
我想在我的 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.
我该如何解决这个问题...
替换
android.support.design.widget.TextInputLayout
与
com.google.android.material.textfield.TextInputLayout
如果您使用 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 上使用最新版本。
在此行后面的 build.gradle 中添加:
implementation 'com.android.support:design:28.0.0'
并在 xml 文件中使用:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/inputLayoutMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dimen_20dp"
android:layout_marginRight="@dimen/dimen_20dp"
android:hint="@string/phone_number"
android:visibility="gone"
android.support.design:layout_constraintTop_toBottomOf="@+id/inputLayoutAppServerUrl">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edtTxtMobile"
style="@style/Style_TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_smartphone"
android:drawablePadding="@dimen/dimen_10dp"
android:inputType="number"
android:singleLine="true"
android:scrollbars="vertical"
android:text="@={SettingViewModel.mMobileNo}"
android:textSize="@dimen/font_13sp" />
</com.google.android.material.textfield.TextInputLayout>
您使用的依赖项是 Android 支持库的一部分,该库现已弃用且不再受 Google 支持。 相反,使用这个:
implementation 'com.google.android.material:material:<version>'
并将<version>
替换为来自Google 的 Maven 存储库或MVN 存储库的最新版本
也许你可以从这里开始阅读更多
对于 android androidX 添加此依赖项
implementation 'com.google.android.material:material:1.2.0'
然后试试
我有类似的问题,用下面的解决方案替换 TextInputLayout 设计模式:
com.google.android.material.textfield.TextInputLayout
如果实现、编译和 api 不起作用,请尝试将类路径与最新版本的材料库一起使用,您可以在Google 的 Maven 存储库中找到最新版本
dependencies {
.....
classpath 'com.google.android.material:material:1.4.0-beta01'
....
}
你在给 id 给 TextInputLayout 时犯了一个错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.