在安卓5.0運行的app, toolbar的左邊會有一些空白,解決方式如下,紅色字部份
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customView = inflator.inflate(R.layout.action_bar_search, null,false);
ActionBar.LayoutParams layout = new ActionBar.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
actionBar.setCustomView(customView, layout);
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
Toolbar parent =(Toolbar) customView.getParent();
parent.setContentInsetsAbsolute(0,0);
}