导航抽屉AppCompat和正常的动作条? [英] Navigation drawer with AppCompat and normal actionbar?
问题描述
我有目前,导航抽屉,一个动作条(无工具栏),并在我的风格定义为母 Theme.AppCompat.Light
。我想留在动作条,但是当我使用的父母,我成为了以下错误:
I have currently, a navigation drawer, a actionbar(no toolbar), and in the styles i defined as parent Theme.AppCompat.Light
. I want to stay at actionbar, but when i use that parent, i become the following error:
"Attempt to invoke virtual method 'android.content.Context android.app.ActionBar.getThemedContext()' on a null object reference"
在code:
in that code:
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
R.layout.navdrawer_item_row,
android.R.id.text1,
new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
}));
有一个人解决的建议来解决? 在此先感谢
Have anyone a solve suggestion to fix? Thanks in advance
推荐答案
您需要使用 getSupportActionBar()
而不是 getActionBar()
。更改您的code这一切的发生。
You need to use getSupportActionBar()
instead of getActionBar()
. Change all occurrences of this in your code.
下面是更正后的code:
Below is the corrected code:
ActionBar ab = getSupportActionBar();
mDrawerListView.setAdapter(new ArrayAdapter<String>(
ab.getThemedContext(),
R.layout.navdrawer_item_row,
android.R.id.text1,
new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
}));
不要忘了导入 android.support.v7.app.ActionBar
另外,在风格父改为 Theme.AppCompat.Light.DarkActionBar
这篇关于导航抽屉AppCompat和正常的动作条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!