通过自定义actionbar布局来改变actionbar的样式,简单方便而且美观,但是有个细节一定要注意就是在高分辨率下左边空白的问题,一般在720以上的分辨率下回发现无论你如何改布局文件总会有一个小的空白
public void setActionBarLayout(int layoutId) {
ActionBar actionBar = getActionBar();
if (null != actionBar) {
//去掉空白
actionBar.setTitle("");
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(layoutId, null);
ActionBar.LayoutParams layout = new ActionBar.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
actionBar.setCustomView(v, layout);
}
然后在相应位置调用并传入布局
setActionBarLayout(R.layout.item_setting_actionbar);