publicclassMainActivityextendsAbBaseActivity{ privatestaticfinalString TAG ="MainActivity"; privateMyApplication myApplication; privateContext mContex ...
- 先來看問題,當我使用ActionBar的時候,設置setCustomView時,會留有空白的處理
- 網上很多朋友說可以修改V7包到19,結果處理的效果也是不理想的.
- 下麵貼出我覺得靠譜的處理代碼
publicclassMainActivityextendsAbBaseActivity{
privatestaticfinalString TAG ="MainActivity";
privateMyApplication myApplication;
privateContext mContext;
privateActionBar mActionBar;
@Override
protectedvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.sliding_menu_content);
myApplication =(MyApplication) getApplication();
mContext =this;
mActionBar = getSupportActionBar();
View actionbarView =LayoutInflater.from(this).inflate(R.layout.actionbar_layout,null);
ActionBar.LayoutParams layoutParams =newActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT);
layoutParams.gravity =Gravity.CENTER_HORIZONTAL |Gravity.CENTER_HORIZONTAL;
mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setCustomView(actionbarView, layoutParams);
Toolbar parent =(Toolbar) actionbarView.getParent();
parent.setContentInsetsAbsolute(0,0);
}
}