自定义 actionbar 两边有空隙问题

来源:互联网 发布:java nested查询 编辑:程序博客网 时间:2024/05/02 00:00

http://www.aichengxu.com/other/3372571.htm


http://www.cnblogs.com/his365/p/6078093.html


主要代码:

  1. @Override
  2. protectedvoid onCreate(Bundle savedInstanceState){
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.sliding_menu_content);
  5. myApplication =(MyApplication) getApplication();
  6. mContext =this;
  7. mActionBar = getSupportActionBar();
  8. View actionbarView=LayoutInflater.from(this).inflate(R.layout.actionbar_layout,null);
  9. ActionBar.LayoutParams layoutParams=newActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
  10. ActionBar.LayoutParams.MATCH_PARENT);
  11. layoutParams.gravity =Gravity.CENTER_HORIZONTAL|Gravity.CENTER_HORIZONTAL;
  12. mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  13. mActionBar.setDisplayShowHomeEnabled(false);
  14. mActionBar.setDisplayShowCustomEnabled(true);
  15. mActionBar.setDisplayShowTitleEnabled(false);
  16. mActionBar.setCustomView(actionbarView, layoutParams);
  17. Toolbar parent =(Toolbar) actionbarView.getParent();
  18. parent.setContentInsetsAbsolute(0,0);
  19. }
  20. }