简体   繁体   English

带有Theme.Material的Android设计支持库

[英]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. 我想在我的应用程序中使用新的设计支持库,从API 21开始。我想使用Theme.Material样式,但它仅适用于Theme.AppCompat样式。 When I use Theme.Material, android return this error: 当我使用Theme.Material时,android会返回此错误:

error inflating class android.support.design.widget.textinputlayout" 错误膨胀类android.support.design.widget.textinputlayout“

How can I resolve it ? 我该如何解决?

Thank you in advance 先感谢您

Ps: Sorry for my bad english, i'm french. Ps:抱歉我的英语不好,我是法国人。

UPDATE: Here is my code 更新:这是我的代码

styles.xml 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 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 的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. TextInputLayout依赖于AppCompat中的资源/属性。 You need to use an AppCompat base theme. 您需要使用AppCompat基本主题。

The AppCompat themes are a parent of the Material based themes on API 21+. AppCompat主题是API 21+上基于材质的主题的父级。 So, you will be using the Material theme. 因此,您将使用Material主题。

Add this line in gradle file : 在gradle文件中添加以下行:

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

then in you *.xml file do like this : 然后在你* .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>

update : if you want use toolbar ,you should change to use AppCompat theme , 更新:如果要使用工具栏,则应更改为使用AppCompat主题,
I'confused about this 我对此感到困惑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android L Theme.Material无法识别 - Android L Theme.Material not being recognized 在android studio中找不到“Theme.Material” - Cannot find “Theme.Material” in android studio Android 中的 Theme.AppCompat 和 Theme.Material 有什么区别? - What is the difference between Theme.AppCompat and Theme.Material in Android? 错误:获取AppCompatActivity与android:Theme.Material不兼容 - Error: Getting AppCompatActivity is not compatible with android:Theme.Material 找不到与给定名称“android:Theme.Material”匹配的资源 - No resource found that matches the given name 'android:Theme.Material' 看不到Theme.Material或Android L的东西 - cannot see Theme.Material or Android L's things 如何同时使用android:Theme.Material和工具栏? - How to use android:Theme.Material and Toolbar together? 如何在styles.xml android中使用android:Theme.Material(Material theme)? - How to use android:Theme.Material (Material theme) in styles.xml android? Android - Material Design 中的 TextView 使用支持库 - Android - TextView in Material Design using Support Library Android Studio 1.3:Theme.Material.Light和Theme.Material提供错误 - Android Studio 1.3: Theme.Material.Light and Theme.Material Giving Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM