Android ActionBar - Push custom view to bottom of screen

前端 未结 2 720
无人共我
无人共我 2021-01-30 12:02

I\'ve got a split ActionBar, and I\'m trying to add functionality almost identical to google play\'s \'Now playing\'..

I can get menu items to appear at the bottom of th

2条回答
  •  孤城傲影
    2021-01-30 12:22

    So I managed to find a dirty solution to this.. Well, dirty in my amateurish opinion..

    In the oncreateOptionsMenu, I've inflated a menu called option_menu like so:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
            new MenuInflater(this).inflate(R.menu.option_menu, menu);
    

    And in the xml for that option_menu item, I've implemented an actionViewClass, and in this case I've used relative layout (I'm guessing I could've just used View..?):

    
    
    
    

    So then I inflated an xml layout, and added it to the layout_item defined in my menu:

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            new MenuInflater(this).inflate(R.menu.option_menu, menu);
            relativeLayout = (RelativeLayout) menu.findItem(R.id.layout_item)
                    .getActionView();
    
            View inflatedView = getLayoutInflater().inflate(R.layout.now_playing,
                    null);
    
            relativeLayout.addView(inflatedView);
    
            return (super.onCreateOptionsMenu(menu));
        }
    

    Please feel free to edit/enhance this answer as you see fit.

提交回复
热议问题