本文介绍了导航抽屉问题(不显示布局预览)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了应用程序并且我想使用导航抽屉菜单,但是当我尝试在导航抽屉

相关

此处未找到layout_preview

我尝试了这个 soultion 来解决这个问题,但不幸的是对我不起作用

这是activity_main_drawer.

activity_main

 包 www.pro.cs_is.com.procsis;导入 android.os.Bundle;导入 android.support.design.widget.FloatingActionButton;导入 android.support.design.widget.Snackbar;导入 android.view.View;导入 android.support.design.widget.NavigationView;导入 android.support.v4.view.GravityCompat;导入 android.support.v4.widget.DrawerLayout;导入 android.support.v7.app.ActionBarDrawerToggle;导入 android.support.v7.app.AppCompatActivity;导入 android.support.v7.widget.Toolbar;导入 android.view.Menu;导入 android.view.MenuItem;公共类 MainActivity 扩展了 AppCompatActivity实现 NavigationView.OnNavigationItemSelectedListener {@覆盖protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);工具栏工具栏 = (工具栏) findViewById(R.id.toolbar);setSupportActionBar(工具栏);DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);ActionBarDrawerToggle 切换 = 新的 ActionBarDrawerToggle(这个,抽屉,工具栏,R.string.navigation_drawer_open,R.string.navigation_drawer_close);drawer.addDrawerListener(toggle);切换.syncState();NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);navigationView.setNavigationItemSelectedListener(this);}@覆盖公共无效 onBackPressed() {DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);如果 (drawer.isDrawerOpen(GravityCompat.START)) {drawer.closeDrawer(GravityCompat.START);} 别的 {super.onBackPressed();}}@覆盖公共布尔 onCreateOptionsMenu(菜单菜单){//给菜单充气;如果它存在,这会将项目添加到操作栏.getMenuInflater().inflate(R.menu.main, menu);返回真;}@覆盖公共布尔 onOptionsItemSelected(MenuItem item) {//在此处处理操作栏项目的点击.操作栏将//自动处理 Home/Up 按钮上的点击,这么长时间//当您在 AndroidManifest.

更新 1:经过多次尝试,将 IDE 更新到 3.1.2 版后似乎是一个普遍问题,直到现在只有一个 解决方案 尽管它类似于预览中的顶部菜单选项

解决方案

删除该行

tools:showIn="navigation_view"

来自 activity_main_drawer.

问题在 AS 3.1.3(2018 年 6 月 8 日)中得到解决并再次出现(2018 年 6 月 16 日)!!!

新的临时解决方法:

  1. 从菜单文件中剪下 tools:showIn="navigation_view" 行.
  2. 关闭菜单文件.
  3. 重新打开它并粘贴该行.
  4. 转到设计并查看应有的菜单.

如果您关闭菜单文件并重新打开它,问题又回来了!仍然没有文本预览.

I created the app and I want to use navigation drawer menu, but when I tried to edit in navigation drawer

to relate

layout_preview not found here

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

this is activity_main_drawer.

<?

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.
解决方案

Remove the line

tools:showIn="navigation_view"

from activity_main_drawer.

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.

这篇关于导航抽屉问题(不显示布局预览)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 08:59
查看更多