Android 在onResume中设置actionbar时出错
在试图设置actionbar的活动的onResume方法中,这里是我的setActionbar代码Android 在onResume中设置actionbar时出错,android,Android,在试图设置actionbar的活动的onResume方法中,这里是我的setActionbar代码 protected void setActionBar() { ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setDisplayHomeAsUpEnabled(false); ac
protected void setActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customActionBar = inflater.inflate(R.layout.actionbar_layout, null);
ivDrawerIconActionbar = (ImageView) customActionBar.findViewById(R.id.iv_drawer_icon);
tvAppName = (TextView) customActionBar.findViewById(R.id.tv_app_name);
ivAppLogo = (ImageView) customActionBar.findViewById(R.id.iv_app_logo);
actionBar.setCustomView(customActionBar);
ll_title = (LinearLayout)customActionBar.findViewById(R.id.ll_title);
ivDrawerIconActionbar.setOnClickListener(this);
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#B44041"));
actionBar.setBackgroundDrawable(colorDrawable);
mDrawerLayout.setDrawerListener(new DrawerListener() {
@Override
public void onDrawerStateChanged(int arg0) {
}
@Override
public void onDrawerSlide(View arg0, float arg1) {
}
@Override
public void onDrawerOpened(View arg0) {
ll_title.setVisibility(View.VISIBLE);
}
@Override
public void onDrawerClosed(View arg0) {
ll_title.setVisibility(View.GONE);
}
});
}
这是onresume方法,这里调用setactionbar()
这里为崩溃添加stacktrace。应用程序崩溃发生在setActionBar方法中。请告诉我为什么会发生崩溃。抱歉使用英语
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
而不是
actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
如果设置了我提到的显示选项,将使用自定义视图 的可能值为:
- 导航模式标准
- 导航模式列表
- 导航\模式\选项卡
actionBar.setNavigationMode(actionBar.DISPLAY\u SHOW\u CUSTOM)代码>
您只需在Actionbar中使用将onResume的代码移动到OnCreate
methodGetting error at Actionbar.setNavigationMode(Actionbar.DISPLAY\u SHOW\u Custom)设置自定义视图即可;
actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);