3

我想在API 21開始我的應用程序中使用新的設計支持庫。 我想使用Theme.Material風格,但它只適用於Theme.AppCompat風格。 當我使用Theme.Material,Android的這個錯誤:Android設計支持庫與Theme.Material

error inflating class android.support.design.widget.textinputlayout"

我該如何解決呢?

預先感謝您

PS:對不起,我的英語不好,我是法國人。

UPDATE: 這裏是我的代碼

styles.xml

<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar"> 
    <item name="android:colorPrimary">@color/primary</item> 
    <item name="android:colorPrimaryDark">@color/primary_dark</item> 
    <item name="android:colorAccent">@color/accent</item> 
    <item name="android:colorControlNormal">@color/control_normal</item> 
    <item name="android:textColorHint">@color/silver</item> 
</style> 

activity.xml

<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:hint="username" 
     android:id="@+id/editText1" /> 

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

的build.gradle

dependencies { 
//compile fileTree(dir: 'libs', include: ['*.jar']) 

compile project(':facebook') 
compile('com.twitter.sdk.android:twitter:[email protected]') { 
    transitive = true; 
    exclude module: 'gson' 
} 

compile 'com.google.android.gms:play-services-plus:7.5.0' 
compile 'com.google.android.gms:play-services-identity:7.5.0' 
compile 'com.android.support:design:22.2.0' 
compile 'com.android.support:support-v13:22.0.0' 
compile 'com.android.support:cardview-v7:22.0.0' 
compile 'com.soundcloud.android:android-crop:[email protected]' 

compile files('libs/volley.jar') 
compile files('libs/gson-2.3.1.jar') 
compile files('libs/httpclient-4.3.3.jar') 
compile files('libs/httpclient-cache-4.3.3.jar') 
compile files('libs/httpcore-4.3.2.jar') 
compile files('libs/httpmime-4.3.3.jar') 
compile files('libs/commons-lang3-3.3.2.jar') 
compile files('libs/hellocharts-library-1.5.5.jar') 
} 
+0

直到現在wh在你已經嘗試過,你能告訴我們 – Soham

回答

8

TextInputLayout依賴於AppCompat中的資源/屬性。您需要使用AppCompat基本主題。

AppCompat themes是API 21+上基於Material的主題的父級。所以,你將使用Material主題。

+0

謝謝你的回答。 – Louis

0

加入這一行gradle這個文件:

compile 'com.android.support:design:22.2.0'

然後你* .xml文件這樣做:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="10dip" 
    android:gravity="center_vertical" 
    android:orientation="vertical" 
    android:padding="10dp"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dip" 
     android:orientation="vertical" 
     android:weightSum="1"> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingTop="4dip" 
      app:hintTextAppearance="@style/textview.small"> 

      <EditText 
       android:id="@+id/et_password" 
       style="@style/textview.medim" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dip" 
       android:layout_marginRight="10dip" 
       android:hint="@string/Password" /> 
     </android.support.design.widget.TextInputLayout> 


    </LinearLayout> 
</LinearLayout> 

更新: 如果你想使用的工具欄,應改爲使用AppCompat主題,
I'Confused about this