自定义ActionBar完全覆盖系统的

时间:2023-03-09 08:11:48
自定义ActionBar完全覆盖系统的
 //加载ActionBar的方法
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.main, menu); setActionBarLayout(R.layout.actionbar_twelve_trailer_pass, this); //layout是自己定义的布局
return true;
} //加载ActionBar的方法
public void setActionBarLayout(int layoutId, Context mContext) {
ActionBar actionBar = getSupportActionBar();
if (null != actionBar) {
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayOptions(DISPLAY_SHOW_CUSTOM);
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(layoutId, new LinearLayout(mContext),
false);
ActionBar.LayoutParams layout = new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
actionBar.setCustomView(v, layout);
}
}