[英]Error in setting actionbar in onResume
在尝试设置actionbar的活动的onResume方法中,这是我的setActionbar代码
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()
@Override
protected void onResume() {
setActionBar();
super.onResume();
}
在这里添加stacktrace崩溃。 setActionBar方法中发生应用程序崩溃请告诉我为什么发生崩溃。
采用
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
代替
actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
如果设置了我提到的显示选项,则将使用您的自定义视图。
setNavigationMode
可能值为:
删除此内容: actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
。
您可以使用actionBar.setDisplayShowCustomCustomEnabled actionBar.setDisplayShowCustomEnabled(true);
在Actionbar中简单地设置“自定义”视图actionBar.setDisplayShowCustomEnabled(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.