Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Crashes after chaning Theme to "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 :/

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

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>
like image 569
Sinan Kara Avatar asked Dec 23 '17 09:12

Sinan Kara


2 Answers

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

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.

Sorry for my bad English.

NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);

like image 172
CENSOR_1337 Avatar answered Oct 28 '22 00:10

CENSOR_1337


Focusing on your style

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

This theme Theme.AppCompat.Light.NoActionBar means you are telling android not to take default ActionBar

and than Later you are calling ActionBar in your MainAcitvity which is the cause for your crash.

Instead use Toolbar and set as ActionBar :

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

Also I think you are using lolipop so add this in your styles.xml :

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

And in your manifest :

<activity android:name=".activity.YourActivity"
          android:theme="@style/AppTheme.NoActionBar"><!-- ADD THIS LINE -->
like image 2
Abubakker Moallim Avatar answered Oct 27 '22 23:10

Abubakker Moallim