ProgressBar in an ActionBar, like GMail app with Refresh

后端 未结 4 1831
情书的邮戳
情书的邮戳 2021-01-30 14:18

I would like to do the same thing than the GMail application on Honeycomb tablets. When you click on the Refresh button, the icon is replaced by a ProgressBar. How can I do this

4条回答
  •  梦谈多话
    2021-01-30 15:19

    Assuming that you already have your menu item setup, you'll need to start by creating two new layouts. One that contains the layout for the normal refresh button, and another that contains the progressbar.

    Once you have them, call the following piece of code to switch between the two layouts. It'll be up to you to decide exactly when it needs to be called a second time in order to switch it back to the refresh icon.

    private void doRefresh(Boolean refreshing, MenuItem menuItem)
    {
        View refreshView;
        LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
        if(refreshing)
            refreshView = inflater.inflate(R.layout.actionbar_indeterminate_progress, null);
        else
            refreshView = inflater.inflate(R.layout.refresh_icon, null);
    
        menuItem.setActionView(refreshView);
    
    }
    

提交回复
热议问题