FEATUREINDETERMINATEPROGRESS supportRequestWindowFeatureWindowFEATUREPROGRESS

This preview shows page 72 - 78 out of 99 pages.

FEATURE_INDETERMINATE_PROGRESS); supportRequestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.indicators); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_progress); toolbar.setTitleTextColor(Color.WHITE); setSupportActionBar(toolba r); if (getSupportActionBar() != null) { getSupportActionBar() .setDisplayHomeAsUpEnabled(true); } ProgressBar toolbarProgress = (ProgressBar) findViewById(R.id.toolbar_spinner); toolbarProgress.setVisibility(View.VISIBLE); toolbarProgress.setProgress(5000); This code demonstrates how to place this type of indeterminate progress indicator on the ActionBar of your Activity screen.
Image of page 72

Subscribe to view the full document.

Adding Progress Indicators to the ActionBar (Cont’d) To use the indeterminate indicator on your Activity object’s ActionBar , you need to request the feature Window.FEATURE_INDETERMINATE_PROGRESS , as previously shown. This shows a small circular indicator in the right side of the ActionBar . For a horizontal ProgressBar style that shows behind the ActionBar , you need to enable Window.FEATURE_PROGRESS . These features must be enabled before your application calls the setContentView() method, as shown in the preceding example.
Image of page 73
Indicating Activity with Activity Bars and Activity Circles When there is no telling how long an operation will take to complete, but you need a way to indicate to the user that an operation is taking place, you should use an activity bar or an activity circle. You define an activity bar or circle exactly like you define a ProgressBar , with one small change: you need to tell Android that the operation running will continue for an indeterminate amount of time by either setting the attribute within your layout file using android:indeterminate , or from within your code by setting the ProgressBar ’s visibility to indeterminate using the setProgressBarIndeterminateVisibility() method.
Image of page 74

Subscribe to view the full document.

Adjusting Progress with Seek Bars You have seen how to display progress to the user. What if you want to give the user some ability to move the indicator for example, to set the current cursor position in a playing media file or to tweak a volume setting? You accomplish this by using the SeekBar control provided by the Android SDK. It’s like the regular horizontal ProgressBar but includes a thumb, or selector, that can be dragged by the user. A default thumb selector is provided, but you can use any drawable item as a thumb.
Image of page 75
Adjusting Progress with SeekBar (Cont’d) <SeekBar android:id="@+id/seekbar1" android:layout_height="wrap_content" android:layout_width="240dp" android:max="500" android:thumb="@drawable/droidsk1" /> Here we have an example of an XML layout resource definition for a simple SeekBar . With this sample SeekBar , the user can drag the thumb named droidsk1 to any value between 0 and 500.
Image of page 76

Subscribe to view the full document.

Adjusting Progress with SeekBar SeekBar seek = (SeekBar) findViewById(R.id.seekbar1); seek.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged( SeekBar seekBar, int progress,boolean fromTouch) { ((TextView)findViewById(R.id.seek_text)) .setText("Value: "+progress);
Image of page 77
Image of page 78
  • Summer '16

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes