ActionBar设置自定义setCustomView()留有空白的问题

  1. 先来看问题,当我使用ActionBar的时候,设置setCustomView时,会留有空白的处理
  2. 网上很多朋友说可以修改V7包到19,结果处理的效果也是不理想的.
  3. 下面贴出我觉得靠谱的处理代码
    1. publicclassMainActivityextendsAbBaseActivity{
    2. privatestaticfinalString TAG ="MainActivity";
    3. privateMyApplication myApplication;
    4. privateContext mContext;
    5. privateActionBar mActionBar;
    6. @Override
    7. protectedvoid onCreate(Bundle savedInstanceState){
    8. super.onCreate(savedInstanceState);
    9. setContentView(R.layout.sliding_menu_content);
    10. myApplication =(MyApplication) getApplication();
    11. mContext =this;
    12. mActionBar = getSupportActionBar();
    13. View actionbarView =LayoutInflater.from(this).inflate(R.layout.actionbar_layout,null);
    14. ActionBar.LayoutParams layoutParams =newActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
    15. ActionBar.LayoutParams.MATCH_PARENT);
    16. layoutParams.gravity =Gravity.CENTER_HORIZONTAL |Gravity.CENTER_HORIZONTAL;
    17. mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    18. mActionBar.setDisplayShowHomeEnabled(false);
    19. mActionBar.setDisplayShowCustomEnabled(true);
    20. mActionBar.setDisplayShowTitleEnabled(false);
    21. mActionBar.setCustomView(actionbarView, layoutParams);
    22. Toolbar parent =(Toolbar) actionbarView.getParent();
    23. parent.setContentInsetsAbsolute(0,0);
    24. }
    25. }
     
     





posted @ 2016-11-18 16:07  his365  阅读(3069)  评论(0编辑  收藏  举报