无法在AppCompatActivity中使用android:Theme.Material

无法在AppCompatActivity中使用android:Theme.Material,第1张

概述首先,我创建了两个样式,一个是值,另一个是值-21.在values/styles.xml中<resources><stylename="AppTheme"parent="Theme.AppCompat"></style><esources>在values-v21/styles.xml中<resources><stylename="AppT

首先,我创建了两个样式,一个是值,另一个是值-21.

在values / styles.xml中

<resources>    <style name="Apptheme" parent="theme.AppCompat"></style></resources>

在values-v21 / styles.xml中

<resources>    <style name="Apptheme" parent="androID:theme.Material"></style></resources>

我的gradle文件(app.gradle)



由于不推荐使用ActionBaractivity,因此我使用了AppCompatActivity.

当我在MainActivity中设置这两个样式值并扩展AppCompatActivity时,我得到了异常:

java.lang.IllegalStateException: You need to use a theme.AppCompattheme (or descendant) with this activity.

我做了两个不同的更改,异常再也没有出现过:

>扩展“androID.app.Activity”而不是v7.AppCompatActivity.
>在values-v21 / styles.xml中更改为“theme.AppCompat”.

如果我想使用设计主题,我应该扩展“androID.app.Activity”吗?

或者,是否有另一种使用材料设计主题的方法?

谢谢.

解决方法:

在styles.xml文件中替换下面的主题.

    <!-- Base application theme. -->    <style name="Apptheme" parent="theme.AppCompat.light.DarkActionbar">        <!-- Customize your theme here. -->    </style>    <style name="MyMaterialtheme" parent="MyMaterialtheme.Base">        <item name="androID:windowContentTransitions">true</item>        <item name="androID:windowAllowEnterTransitionOverlap">true</item>        <item name="androID:windowAllowReturnTransitionOverlap">true</item>    </style>    <style name="MyMaterialtheme.Base" parent="theme.AppCompat.light.DarkActionbar">        <item name="windowNoTitle">true</item>        <item name="windowActionbar">false</item>        <item name="colorPrimary">@color/colorPrimary</item>        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>        <item name="colorAccent">@color/colorAccent</item>    </style></resources>

并使用在MainActivity中扩展AppCompatActivity.

最后在Manifestfile中使用此主题.

   <application            androID:allowBackup="true"            androID:icon="@mipmap/ic_launcher"            androID:label="@string/app_name"            androID:theme="@style/MyMaterialtheme">    </application>

Gradle文件依赖项.

    dependencIEs         {         compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.androID.support:appcompat-v7:23.3.0' compile 'com.androID.support:recyclervIEw-v7:23.1.1' compile 'com.androID.support:cardvIEw-v7:23.2.1' // For NavigationVIEw Using Menu 'compile 'com.androID.support:design:23.3.0' // For Google Map compile 'com.Google.androID.gms:play-services-maps:9.8.0'       } 

根据需要编辑我的主题.
希望它能帮助……

总结

以上是内存溢出为你收集整理的无法在AppCompatActivity中使用android:Theme.Material全部内容,希望文章能够帮你解决无法在AppCompatActivity中使用android:Theme.Material所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1108571.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存