简体   繁体   中英

Android design support library with Theme.Material

I would like to use the new design support library in my application beginning with the API 21. I want to use Theme.Material style but it's work only with Theme.AppCompat style. When I use Theme.Material, android return this error:

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

How can I resolve it ?

Thank you in advance

Ps: Sorry for my bad english, i'm french.

UPDATE: Here is my code

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:1.1.0@aar') {
    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:0.9.10@aar'

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')
}

TextInputLayout relies on resources/attributes in AppCompat. You need to use an AppCompat base theme.

The AppCompat themes are a parent of the Material based themes on API 21+. So, you will be using the Material theme.

Add this line in gradle file :

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

then in you *.xml file do like this :

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

update : if you want use toolbar ,you should change to use AppCompat theme ,
I'confused about this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM