0

Android 라이브러리 프로젝트에서 TextInputLayout을 사용하려고합니다. 하지만 XML을 사용하여 레이아웃을 설계하는 동안 오류가 발생하고 또한 'android.view.InflateException'프로젝트를 실행하는 동안. 내 XML 레이아웃 파일은 targetSDK 24과 compileSDK는 빌드 도구 버전 24.0.1 24입니다, 또한 내가Android 라이브러리 프로젝트에서 TextInputLayout을 사용하는 중 오류가 발생했습니다.

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) 

프로젝트 minSDK가 16 오류가 아래 얻을 레이아웃 디자인 창에서

<?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> 

입니다. 또한 앱과 라이브러리 모듈 모두에서 아래의 gradle 종속성을 추가했습니다.

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' 
+0

이보기가 포함 된 XML 파일 게시 – mklimek

+0

@mklimek XML 레이아웃 파일로 업데이트했습니다 – anandprabhu

답변

0

앱을 확인 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> 

내부 TextInputEditText를 사용해야하는 것은 마지막으로 Theme.AppCompat.Light.DarkActionBar

, AndroidManifest.xml을처럼 확장 APPCOMPAT 테마

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

또는 기타를 사용합니다 :

<application android:theme="@style/AppTheme"> 
+0

사실 내 레이아웃 파일은 앱 내부가 아닌 라이브러리 모듈 안에 있습니다. 주 앱의 테마 설정을 시도했지만 오류가 라이브러리 모듈 내부에서 해결되지 않았습니다. – anandprabhu

+0

귀하의 활동이 테마 설정보다 우선하지 않도록하십시오. – mklimek

1

마지막으로 AppCompat 테마를 TextInputLayout에 직접 추가하면 정상적으로 작동합니다. 난 그냥 아래에 언급 된 게시물에 제공되는 솔루션, 나는 아래처럼 내 레이아웃 파일을 업데이트

TextInputLayout AppCompat Theme

,

<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> 
0

하여 활동해야이 AppCompatActivity를 확장을 따랐다. 그런 다음 그것은 나를 위해 일하고 있습니다.