Android Lollipop, AppCompat ActionBar custom view doesn't take up whole screen width

问题:

So, I just updated my codebase to Lollipop, and I'm having issues with the Action Bar. 所以,我刚刚将我的代码库更新为Lollipop,而且我遇到了Action Bar的问题。 I'm using AppCompat and ActionBarActivity, and inflating a custom view. 我正在使用AppCompat和ActionBarActivity,并为自定义视图充气。 It seems that the custom view no longer takes up the whole width of the screen, leaving a thin strip on the left 似乎自定义视图不再占据屏幕的整个宽度,在左侧留下一条细条

建筑用19 Way it used to look 过去的样子

建筑用21 Way it looks now 它看起来现在的样子

This is the code I'm using to set up the Action Bar. 这是我用来设置Action Bar的代码。 Anyone have any ideas? 有人有主意吗?

final ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setCustomView(R.layout.action_bar_content_search_custom_view);
    actionBar.setBackgroundDrawable(null);
    // actionBar.setStackedBackgroundDrawable(null);
    TextView title = (TextView) actionBar.getCustomView().findViewById(R.id.action_bar_title);
    title.setText(R.string.youtube);
    ImageView back = (ImageView) actionBar.getCustomView().findViewById(R.id.action_bar_back);
    back.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}

Edit 编辑

Taking out the custom view and changing the background now takes up the whole width. 取出自定义视图并更改背景现在占用整个宽度。 So the issue is, how can we make a CustomView take up the whole width of the ActionBar? 问题是,我们如何让CustomView占用ActionBar的整个宽度?


解决方案:

参考: https://stackoom.com/en/question/1muXJ
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章