navigation drawer issue (not showing layout preview)
Asked Answered
B

6

12

I created the app and I want to use navigation drawer menu, but when I tried to edit in navigation drawer xml, then the problem "Waiting for build to finish..." happened and I don't see layout previw on left side of android studio

to relate

activity_main_drawer

layout_preview not found here

layout_preview

I tried this soultion to solve this issue but unfortunately not working for me

this is activity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/articles"
            android:icon="@drawable/ic_menu_camera"
            android:title="@string/articles" />
        <item
            android:id="@+id/windows"
            android:icon="@drawable/ic_menu_gallery"
            android:title="@string/windows" />
        <item
            android:id="@+id/linux"
            android:icon="@drawable/ic_menu_slideshow"
            android:title="@string/linux" />
        <item
            android:id="@+id/miscellaneous_devices"
            android:icon="@drawable/ic_menu_manage"
            android:title="@string/miscellaneous_devices" />

        <item
            android:id="@+id/information_security"
            android:icon="@drawable/ic_menu_manage"
            android:title="@string/information_security" />

        <item
            android:id="@+id/facebook"
            android:icon="@drawable/ic_menu_manage"
            android:title="@string/facebook" />
    </group>

    <item android:title="Communicate">
        <menu>
            <item
                android:id="@+id/nav_share"
                android:icon="@drawable/ic_menu_share"
                android:title="Share" />
            <item
                android:id="@+id/nav_send"
                android:icon="@drawable/ic_menu_send"
                android:title="Send" />
        </menu>
    </item>

</menu>

activity_main

    package www.pro.cs_is.com.procsis;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);



        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.miscellaneous_devices) {
            // Handle the camera action
        } else if (id == R.id.articles) {

        } else if (id == R.id.windows) {

        } else if (id == R.id.linux) {

        } else if (id == R.id.facebook) {

        } else if (id == R.id.information_security) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

Update 1 : After many attempts it's seems a general Issue after update IDE to version 3.1.2, till now there's only one solution which @mtak suggested although it is similar to the top menu options in the preview

Bedrock answered 6/5, 2018 at 15:21 Comment(0)
U
21

Remove the line

tools:showIn="navigation_view"

from activity_main_drawer.xml and rebuild. This solved the same problem for me. Don't know why!!!

Problem solved in AS 3.1.3(8 June 2018) and reappeared again (16 June 2018)!!!

New temporary workaround:

  1. Cut the line tools:showIn="navigation_view" from the menu file.
  2. Close the menu file.
  3. Reopen it and paste the line.
  4. Go to design and see the menu as it should be.

If you close the menu file and reopen it the problem comes back! Still no preview in Text.

Unwished answered 7/5, 2018 at 20:4 Comment(4)
Using AS 3.1.3 Still have the issueEinsteinium
You're right DanMossa. I don't know what's happening, the only update since the day I saw that problem was solved, is upgrading to Kotlin 1.50.Unwished
worked for me too. thanks. This is Sept 22nd 2018, still issue is thereLecherous
Hi, I'm facing the same issue. After trying your solutions, it still doesn't work.Heartsease
M
4

You can try the following:

  • Run Build then try to see the preview again

  • Close the current layout,open another then reopen again

Mccarthy answered 6/5, 2018 at 17:8 Comment(4)
unfortunately this not working also, this caused hide the layout preview in Text modeBedrock
what does hide layout in text mode mean?Mccarthy
I see the preview in design, and I see Render problem "Failed to find style 'coordinatorLayoutStyle' in current theme"Bedrock
that's because you dont have any coordinatorlayoutstyle,its coordinatorlayout,also try File" → "Invalidate Caches / Restart"Mccarthy
P
1

Because you extend AppCompatActivity, you need to make sure that in your styles.xml your AppTheme is a descendant of AppCompat

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

That worked for me while the accepted answer for not that helping.

Polypropylene answered 14/4, 2019 at 13:31 Comment(0)
M
0

I have found the solution. Remove these two tool lines and close/reopen:

xmlns:tools = "http://schemas.android.com/tools"

tools:showIn = "navigation_view"
Microscopium answered 21/9, 2018 at 18:15 Comment(0)
E
0

Actually this problem is because you have extended your activity with AppComactActivity and your theme parent is not the Theme.AppCompat use this theme as your default in manifest.xml under application tag. your style should look like as

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


Embryology answered 1/5, 2021 at 10:54 Comment(0)
S
-2

rebuilduing the project worked for me

Svetlanasvoboda answered 22/3, 2019 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.