将主题更改为“NoActionBar"后应用程序崩溃; [英] App Crashes after chaning Theme to "NoActionBar"

查看:44
本文介绍了将主题更改为“NoActionBar"后应用程序崩溃;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将我的应用主题更改为Theme.AppCompat.Light.NoActionBar".但是在我更改它之后,应用程序崩溃了.我找不到问题出在哪里:/

Hi I have to change my App theme to "Theme.AppCompat.Light.NoActionBar". But after I changed it, the app crashes. I could not find out where the problem is :/

我的目标是在工具栏上扩展我的导航抽屉.但为此,我需要NoActionBar"功能.我希望有人可以帮助我.感谢转发!

My goal is to expand my Navigation Drawer over the toolbar. But for that, I need the "NoActionBar" function. I hope someone can help me out. Thanks forwards!

这是来自调试器的错误代码:

That is the error code from the debugger:

12-23 11:04:28.292 1410-1421/? E/ANDR-PERF-LOCK: Failed to apply optimization for resource: 4 level: 0

这是我的styles.xml代码:

That is my styles.xml code:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:listDivider">@android:color/transparent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

推荐答案

1.转到MainActivity.java文件
2.注释这行代码
//NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
3.crash应该修复

1.Go to MainActivity.java file
2.Comment this line of code
//NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
3.crash should be fixed

原因您正在使用底部导航活动",它崩溃的原因是因为 java 尝试从 Actionbar 获取对象,当禁用 Actionbar 时,它返回 null 因为我们没有操作栏,要解决此问题,您需要发表评论或删除代码如果您转到 MainActivity.java(如果您使用的是 java),您将在第 26 行看到此代码,它会尝试设置操作栏.我们可以将代码注释掉,它应该可以正常工作.

Reason why You're using "Bottom Navigation Activity", the reason it crashing because java tries to get the object from Actionbar, When the Actionbar is disabled it returns null cause we don't have an action bar, To fix this you need to comment or remove code out if you go to MainActivity.java (in case you're using java) you will see this code on line 26 and it tries to get set up the action bar. we can comment the code out and it should work fine.

抱歉我的英语不好.

NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);

这篇关于将主题更改为“NoActionBar"后应用程序崩溃;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆