2016年7月6日 星期三

android 5.0 toolbar 左邊的空白

在安卓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);
        }