Android Split Action Bar with Action Items on the top and bottom?

前端 未结 5 2255
滥情空心
滥情空心 2020-11-27 12:05

Is there a way to specify some action items to the top part of the Split Action Bar while the others go to the bottom? Or is it all or nothing, whereby all the action items

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 12:36

    To solve this I used a custom view as my action bar:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    
        View view = View.inflate(getApplicationContext(), R.layout.actionbar,
                null);
        actionBar.setCustomView(view);
    
    }
    

    and then for the bottom bar I inflated my menu view or whatever you want to appear at bottom:

     @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.browser_main, menu);
        RelativeLayout relativeLayout = (RelativeLayout) menu.findItem(
                R.id.layout_item).getActionView();
    
        View inflatedView = getLayoutInflater().inflate(
                R.layout.media_bottombar, null);
    
        relativeLayout.addView(inflatedView);
    
        return true;
    }
    

    In the Android Manifest, I also include (android:uiOptions="splitActionBarWhenNarrow") like this:

     ....
    

提交回复
热议问题