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

xiaoxiao2021-02-28  120

/** * 自定义导航视图 * @return */ protected void initCustomActionBar() { ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER); View mActionBarView = LayoutInflater.from(this).inflate(R.layout.actionbar_custom, null); mActionbar = getSupportActionBar(); if (mActionbar == null){ return; } mActionbar.setCustomView(mActionBarView, lp); mActionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); // 返回箭头(默认不显示) mActionbar.setDisplayHomeAsUpEnabled(false); // 左侧图标点击事件使能 mActionbar.setHomeButtonEnabled(true); // 使左上角图标(系统)是否显示 mActionbar.setDisplayShowHomeEnabled(false); // 显示标题 mActionbar.setDisplayShowTitleEnabled(false); //显示自定义视图 mActionbar.setDisplayShowCustomEnabled(true); //去除系统 action两端的留白 Toolbar parent =(Toolbar) mActionBarView.getParent(); parent.setContentInsetsAbsolute(0,0); //标题 tvTitle = (TextView) mActionbar.getCustomView().findViewById(R.id.id_top_bar_title); ImageButton setImgBtn = (ImageButton) mActionBarView.findViewById(R.id.id_right_btn); backBtn = (ImageButton) mActionBarView.findViewById(R.id.id_left_back_btn); setImgBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { L.e("这是设置按钮"); } }); }
转载请注明原文地址: https://www.6miu.com/read-96696.html

最新回复(0)