问题描述
我创建了该应用程序,并且想使用导航抽屉菜单,但是当我尝试在导航抽屉xml中进行编辑时,出现了等待构建完成..."的问题,并且我看不到布局的前一页android studio的左侧
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
联系
在这里找不到layout_preview
layout_preview not found here
我尝试了灵魂来解决此问题,但不幸的是对我不起作用
I tried this soultion to solve this issue but unfortunately not working for me
这是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;
}
}
推荐答案
删除行
tools:showIn="navigation_view"
从activity_main_drawer.xml进行重建.这为我解决了同样的问题.不知道为什么!
from activity_main_drawer.xml and rebuild.This solved the same problem for me.Don't know why!!!
问题已在AS 3.1.3中解决(2018年6月8日),并且再次出现(2018年6月16日)!!!
Problem solved in AS 3.1.3(8 June 2018) and reappeared again (16 June 2018)!!!
新的临时解决方法:
- 从菜单文件中剪切行
tools:showIn="navigation_view"
. - 关闭菜单文件.
- 重新打开它并粘贴行.
- 进行设计并按原样查看菜单.
- Cut the line
tools:showIn="navigation_view"
from the menu file. - Close the menu file.
- Reopen it and paste the line.
- 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.
这篇关于导航抽屉问题(不显示布局预览)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!