[英]Error in setting actionbar in onResume
In onResume method of activity trying to set actionbar here is my code for setActionbar 在尝试设置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);
}
});
}
and this is onresume method,here calling setactionbar() 这是onresume方法,在这里调用setactionbar()
@Override
protected void onResume() {
setActionBar();
super.onResume();
}
here adding stacktrace for crash. 在这里添加stacktrace崩溃。 App crash is happening in setActionBar method pls tell me why crash is happening.sorry for english setActionBar方法中发生应用程序崩溃请告诉我为什么发生崩溃。
Use 采用
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
instead of 代替
actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
Your custom view will be used if the display option I mentioned is set. 如果设置了我提到的显示选项,则将使用您的自定义视图。
Possible values for setNavigationMode
are : setNavigationMode
可能值为:
Remove this : actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
删除此内容: actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
. 。
You can simply set Custom view in Actionbar with actionBar.setDisplayShowCustomEnabled(true);
您可以使用actionBar.setDisplayShowCustomCustomEnabled actionBar.setDisplayShowCustomEnabled(true);
在Actionbar中简单地设置“自定义”视图actionBar.setDisplayShowCustomEnabled(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.