-2

I need a progress bar in my action bar. I am able to get it using the following code:-

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.main_screen);
    progress = (LinearLayout) findViewById(R.id.progress);
    setProgressBarIndeterminateVisibility(Boolean.FALSE);
    this.setProgressBarIndeterminate(true);
}

However, I am also seeing a spinner with progress bar. Can someone tell me how to hide the spinner.Also i need to move the progress bar below the action bar.

DroidDev
  • 1,527
  • 4
  • 20
  • 42
shilpa
  • 1
  • 1
  • 2
    The Toolbar was introduced in android lollipop. Have a look at this post http://stackoverflow.com/questions/26440879/how-do-i-use-drawerlayout-to-display-over-the-actionbar-toolbar-and-under-the-st/26440880 and also go read this dev post(http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html) at the bottom of the post you will find the toolbar. – the-ginger-geek Nov 04 '14 at 10:57
  • Format well before posting question – Amy Nov 04 '14 at 11:05
  • Do you need an indeterminate progress bar or an horizontal progressbar? – joao2fast4u Nov 04 '14 at 11:09
  • i need a horizontal progress bar. I know i have added two requestWindowFeatures, but my horizontal bar does not appear without "requestWindowFeature(..)" – shilpa Nov 04 '14 at 11:13
  • @shilpa I think you have set 2 style at a same time, that is why you can see spinner and progress bar both. – Pratik Dasa Nov 04 '14 at 11:16
  • @pratt but if i remove the second feature, then neither progress bars are visible. – shilpa Nov 04 '14 at 11:19
  • If you want a progress bar below the Action Bar, it has nothing to do with the Action Bar. Just place a progressdialog at you activity's layout. – joao2fast4u Nov 04 '14 at 11:23
  • @shilpa how it is posible? I dont think so, you have to check for it. – Pratik Dasa Nov 04 '14 at 11:23
  • possible duplicate of [ProgressBar under Action Bar](http://stackoverflow.com/questions/13934010/progressbar-under-action-bar) – DroidDev Nov 04 '14 at 11:27
  • @shilpa Check these https://github.com/chrisbanes/ActionBar-PullToRefresh , https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-Stock – Piyush Nov 04 '14 at 11:39

1 Answers1

-1

Progress bar is used when we are supposed to perform action in background. You can use it wherever you need it. Following example may be helpful:

private ProgressDialog PDialog;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.examplelayout);

    new Example().execute();
}

class Example extends AsyncTask<Void, Void, String> {
    // private ProgressDialog dialog;       
    private ProgressDialog dialog = new ProgressDialog(examplelayout.this);

    @Override
    protected void onPreExecute() {
        // This progressbar will load util tast in doInBackground method loads
        pDialog = new ProgressDialog(examplelayout.this);
        pDialog.setMessage("Loading...");
        pDialog.setCancelable(true);
        pDialog.setTitle("In progress...");     
        pDialog.setIcon(android.R.drawable.stat_sys_download);
        pDialog.setMax(100);         
        pDialog.show();
    }

    @Override
    protected String doInBackground(Void... params) {
        YourMethod();//perform any action
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        dialog.dismiss();
    }
}
Andrew T.
  • 4,701
  • 8
  • 43
  • 62
  • Not sure this is what the OP wanted. It will show a dialog with progress bar instead, not in Action Bar. – Andrew T. Nov 05 '14 at 01:02