【问题标题】:Error inflating TextInputLayout when used with ViewPager与 ViewPager 一起使用时膨胀 TextInputLayout 时出错
【发布时间】:2015-08-07 09:52:41
【问题描述】:

看起来TextInputLayoutViewPager 中不起作用。

错误是:

膨胀类 android.support.design.widget.TextInputLayout 时出错

AppcompatDesign library 添加。 Theme 是正确的。

我使用PageAdapter 膨胀和填充ViewPager

TextInputLayout 视图在应用程序的所有其他部分膨胀得很好

layout 我为ViewPager 膨胀。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

  <android.support.design.widget.TextInputLayout
    android:id="@+id/text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
      android:id="@+id/edit_text"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="My Edit Text" />

  </android.support.design.widget.TextInputLayout>

</LinearLayout>

【问题讨论】:

  • @IntelliJAmiya,除了ViewPager,视图在其他任何地方膨胀,所以它不是主题、库或任何东西。
  • 整个 logcat 是什么?它抛出了哪个异常?或者这是一个“预览”错误?
  • 请在 logcat 中发布详细的错误信息!
  • @Eugene 你找到解决方案了吗?

标签: android android-viewpager android-textinputlayout


【解决方案1】:

使用这个

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat">

您还必须使用 AppCompatActivity 而不是 Activity 来扩展您的类

【讨论】:

    【解决方案2】:

    您应该尝试一些方法来解决问题。

    • 从 AppCompatActivity 扩展您的活动
    • 从 android.support.v4.app.Fragment 扩展您的(对话框)片段。
    • 使用最新版本的设计库。
    • 不要使用 EditText,而是使用 android.support.v7.widget.AppCompatEditText。例如:

          <android.support.design.widget.TextInputLayout
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          app:errorEnabled="true">
      
                          <android.support.v7.widget.AppCompatEditText
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:hint="First Name"
                              android:inputType="textPersonName"
                              android:singleLine="true" />
      
          </android.support.design.widget.TextInputLayout>
      

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,但上述解决方案均不适合我。最后,我将 PagerAdapter 切换为 FragmentStatePagerAdapter 并使用 Fragment 实现整个事情。

      您可以参考this link

      对于我的实验,我调整了演示并将 TextInputLayout 插入到它的 ViewPager 中,一切正常。

      【讨论】:

        猜你喜欢
        • 2016-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-20
        • 2016-07-02
        • 2016-12-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多