【发布时间】: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