Restore default actionbar layout

前端 未结 2 1566
臣服心动
臣服心动 2021-02-14 05:41

I apply a custom View to the ActionBar, like this

// Inflate the \"Done/Discard\" custom ActionBar view.
LayoutInflater inflater = (La         


        
相关标签:
2条回答
  • 2021-02-14 06:02
    ActionBar actionbar;
    
    actionbar = getActionBar();
    
    Button cls = (Button)findViewById(R.id.btn_close);
    
    cls.setOnClickListener(new OnClickListener(){           
        public void onClick(View view){
           actionbar.setDisplayShowCustomEnabled(false);                
       }            
    });
    

    Note: The button with id 'btn_close' was located in the custom actionbar layout.This function was written in mainactivity.

    Hope this Helps!!

    0 讨论(0)
  • 2021-02-14 06:17

    Show/hide custom actionbar view

    Since you only added a custom view to the bar without removing the title it should be sufficient to hide that custom View. You can use method setDisplayShowCustomEnabled(). Just call:

    getActivity().getActionBar().setDisplayShowCustomEnabled(false);
    

    And enable home functionality again:

    getActivity().getActionBar().setDisplayShowHomeEnabled(true);
    

    (Note in all code examples use getSupportActionBar() instead of getActionBar() if you're using actionbar compat. Also the getActivity() is only needed from fragments, in activities refer to the activity itself, in most cases this)

    Restore actionbar title

    If however you also removed the title when creating your custom view you'll have to enable that again also.

    getActivity().getActionBar().setDisplayShowTitleEnabled(true);
    

    Restore completely

    You can also call the setDisplayOptions() method with a combination of options to reconfigure the actionbar in one call. The below example removes the custom view and shows the title.

    getActivity().getActionBar().setDisplayOptions(
        ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    

    See Android API docs for more details on these options.

    0 讨论(0)
提交回复
热议问题