In onResume method of activity trying to set actionbar here is my code for 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()
@Override
protected void onResume() {
setActionBar();
super.onResume();
}
here adding stacktrace for crash. App crash is happening in setActionBar method pls tell me why crash is happening.sorry for english
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 :
Remove this : actionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
.
You can simply set Custom view in Actionbar with actionBar.setDisplayShowCustomEnabled(true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.