ActionBar设置自定义setCustomView()留有空白的问题
- 先来看问题,当我使用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);
}
}
世界上没有什么事情是跑步解决不了的,如果有,那就再跑一会!