How can I position my actionbar list navigation on the right side?

后端 未结 4 688
忘掉有多难
忘掉有多难 2021-01-02 08:56

\"enter

This image demonstrats what I need to do. I need the dropdown menu to always s

4条回答
  •  轮回少年
    2021-01-02 09:23

    Add UI components at the Right side of Actionbar using ToolBar:

    Check this link for more details of ToolBar.

    Screenshot attached.

    enter image description here

    toolbar.xml

    
    
    
        
    
    
    
        
    
    

    Style for Application

    
    
        
        
    
        
    
        
    
    

    Include xml in activity_main.xml

    
    

    Your Activity must be extends AppCompatActivity

    on onCreate of Activity

    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    

    on onCreateView of Fragment

    Toolbar  mToolBar = (Toolbar) getActivity().findViewById(R.id.toolbar_actionbar);
    RelativeLayout rlToolBarMain = (RelativeLayout)mToolBar.findViewById(R.id.rlToolBarMain);
    
    Spinner mSpinner = new Spinner(getActivity());
    String[] frags = new String[]{
                    "category1",
                    "category2",
                    "category3",
            };
    ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1,frags);
    mSpinner.setAdapter(arrayAdapter);
    rlToolBarMain.addView(mSpinner);
    

    Done

提交回复
热议问题