简体   繁体   English

错误:获取AppCompatActivity与android:Theme.Material不兼容

[英]Error: Getting AppCompatActivity is not compatible with android:Theme.Material

I am trying add a Navigation Drawer to my app using Material Theme. 我正在尝试使用Material Theme将导航抽屉添加到我的应用程序中。 Following this tutorial here to start . 按照本教程从这里开始

The output should look like this GIF : 输出应该看起来像这个GIF

Looks like AppCompatActivity is not compatible with android:Theme.Material , dont understand why? 看起来AppCompatActivity与android:Theme.Material不兼容 ,不明白为什么?

My res/styles.xml : 我的res/styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

<!-- your theme inherits from the material theme -->
<style name="MaterialTheme" parent="android:Theme.Material">
    <!-- theme customizations -->
</style>

My Activity Code, simply extends AppCompatActivity : 我的活动代码仅扩展了AppCompatActivity

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main);
    setContentView(R.layout.mainactivity);
......

Now, my manifest, not that I am trying to use: the MaterialTheme : 现在,我的清单不是我要使用的MaterialThemeMaterialTheme

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxx.xxxxxxxx.xxx" >

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MaterialTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

This is the error I get: 这是我得到的错误:

java.lang.RuntimeException: Unable to start activity     ComponentInfo{com.focusonanywhere.www.focusonanywhere/com.focusonanywhere.www.focusonanywhere.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at      com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:122)
        at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
        at      com.focusonanywhere.www.focusonanywhere.MainActivity.onCreate(MainActivity.java:45)
        at android.app.Activity.performCreate(Activity.java:5990)
        at   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
        at        android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at            android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at          com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Looks like AppCompatActivity is not compatible with android:Theme.Material, dont understand why? 看起来AppCompatActivity与android:Theme.Material不兼容,不明白为什么?

The appcompat-v7 action bar backport requires the use of Theme.AppCompat and its sub-themes (eg, Theme.AppCompat.Light ). appcompat-v7操作栏向后移植需要使用Theme.AppCompat及其子主题(例如Theme.AppCompat.Light )。 That's just the nature of that library. 那只是那个图书馆的本质。 Your choices are: 您的选择是:

  1. Not use AppCompatActivity and use the native action bar, or 不使用AppCompatActivity并使用本机操作栏,或者

  2. Not use Theme.Material and instead use Theme.AppCompat 不使用Theme.Material ,而是使用Theme.AppCompat

声明:本站的技术帖子网页,遵循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 带有Theme.Material的Android设计支持库 - Android design support library with Theme.Material Android Studio 1.3:Theme.Material.Light和Theme.Material提供错误 - Android Studio 1.3: Theme.Material.Light and Theme.Material Giving Error Android 中的 Theme.AppCompat 和 Theme.Material 有什么区别? - What is the difference between Theme.AppCompat and Theme.Material in Android? 检索父项时出错:找不到与给定名称“ Android:Theme.Material”匹配的资源 - Error retrieving parent for item: No resource found that matches the given name '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?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM