【问题标题】:Can't add navigation icon to activity无法将导航图标添加到活动
【发布时间】:2017-09-22 04:22:16
【问题描述】:
    public void setContentView(int layoutResID)
    {
        DrawerLayout fullView = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base, null);
        FrameLayout activityContainer = (FrameLayout) fullView.findViewById(R.id.activity_content);
        getLayoutInflater().inflate(layoutResID, activityContainer, true);
        super.setContentView(fullView);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        final ActionBar actionBar = getSupportActionBar();

        if (actionBar != null)
        {
            actionBar.setDisplayHomeAsUpEnabled(true);
            mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close)
            {

                public void onDrawerClosed(View view)
                {
                    supportInvalidateOptionsMenu();
                    //drawerOpened = false;
                }

                public void onDrawerOpened(View drawerView)
                {
                    supportInvalidateOptionsMenu();
                    //drawerOpened = true;
                }
            };
            mDrawerToggle.setDrawerIndicatorEnabled(true);
            drawerLayout.setDrawerListener(mDrawerToggle);
            mDrawerToggle.syncState();
        }
    }
}

我想将导航抽屉图标添加到此导航抽屉活动。现在我已经编辑了代码,但现在错误应用程序在启动时停止

【问题讨论】:

  • 导航箭头图标还是汉堡图标?
  • 汉堡图标。因为它是抽屉活动,我需要将此活动扩展到所有其他活动
  • 致命异常:java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.arun4fms.myapplication/com.example.arun4fms.myapplication.MainActivity}:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法 'void android.support.v4.widget.DrawerLayout.setDrawerListener(android.support.v4.widget.DrawerLayout$DrawerListener)'
  • 您将 DrawerLayout 命名为 fullView 而不是 drawerLayout

标签: java android


【解决方案1】:

也许您可以尝试将其添加到布局文件中修改 xml 代码,或按照本教程获取更多信息Android Sliding Menu

【讨论】:

  • 所以如果你打开抽屉,你可以让图标在代码中可见或消失
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-13
  • 2020-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多