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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章