0

I am trying to use the TextInputLayout inside an Android Library project. But i am getting an error while designing the layout using XML and also 'android.view.InflateException' while executing the project. My XML layout file is

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <CustomViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="bottom">

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:imeOptions="actionDone"
                android:inputType="textNoSuggestions" />
        </android.support.design.widget.TextInputLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Skip"/>
    </RelativeLayout>
</RelativeLayout>

In the layout design window also i get below error

java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
    at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36)
    at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:184)
    at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:177)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$53(RenderTask.java:659)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Projects minSDK is 16, targetSDK is 24 and compileSDK is 24 with build tools version 24.0.1. Also I have added the below gradle dependencies in both the app and library modules.

compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'

3 Answers3

1

Finally adding an AppCompat theme directly to the TextInputLayout makes it work fine. I just followed the solution provided in the below mentioned post,

TextInputLayout AppCompat Theme

I updated my layout file like below,

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Theme.AppCompat">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:imeOptions="actionDone"
            android:inputType="textNoSuggestions" />
    </android.support.design.widget.TextInputLayout>
Community
  • 1
  • 1
0

You should use TextInputEditText inside TextInputLayout

 <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

ensure your app uses AppCompat theme

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

or other which extends it like Theme.AppCompat.Light.DarkActionBar

Finally, AndroidManifest.xml:

<application android:theme="@style/AppTheme">
klimat
  • 24,711
  • 7
  • 63
  • 70
  • Actually my layout file is inside library module not inside an app. I tried setting the theme for the main app but the error is not resolved inside the library module. – anandprabhu Nov 21 '16 at 16:02
  • ensure your activity doesn't override theme setting – klimat Nov 21 '16 at 16:06
0

your Activity must extends AppCompatActivity. Then only it is working for me.

shyam.y
  • 1,441
  • 1
  • 16
  • 17