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. }
     
     





转载于:https://www.cnblogs.com/his365/p/6078093.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值