ActionBar with custom layout does not occupy full screen width on Android 4.4.2 (KitKat)

前端 未结 2 1163
遇见更好的自我
遇见更好的自我 2021-01-13 05:19

I want to display an Action Bar with a custom layout. The custom layout has three ImageViews, one in the centre and the other two on the left & right ends of the action

相关标签:
2条回答
  • 2021-01-13 05:23

    It's not a gap, it's a menu overflow button to the right. If you look closely you can see three dots button.

    You've chosen the wrong theme because you can hardly see it. Use Theme.Compat.Light.DarkActionBar if your ActionBar is dark and you need the light theme.

    On devices that don't have physical menu button (mostly new ones) the menu overflow button is shown.

    You can't remove it unless you disable menus.

    You can use splitActionBarWhenNarrow uiOptions which will split the ActionBar so that the menu part will be at the bottom one, but that will be only for vertical orientation of medium screens and probably not what you need.

    Take a look at the ActionBar Patterns doc and Menus UI doc

    0 讨论(0)
  • 2021-01-13 05:46

    In my case I have solved the issue bypassing the invocation of the LayoutInflater.

    So one should simply replace this code:

    View actionBarView = LayoutInflater.from(this).inflate(R.layout.custom_actionbar, null); 
    actionBar.setCustomView(actionBarView, lp);
    

    with this code:

    actionBar.setCustomView(R.layout.custom_actionbar);
    
    0 讨论(0)
提交回复
热议问题