0

I am developing an app that display news from different sources. When the news is clicked it opens an activity that consists of a WebView to deliver the Web Page related to the news. Together with the WebView I have implemented a ProgressBar to display the progress in loading the page. I do not want it to take the space of the content so I tried to implement it at the bottom of the ActionBar. But the result wasn't what I excepted and it is shown in the image below.

<code>ProgresBar</code> In <code>ActionBar</code>

The code I have used is like below:

// create new ProgressBar and style it
        final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
        progressBar.setLayoutParams(new android.app.ActionBar.LayoutParams(android.app.ActionBar.LayoutParams.MATCH_PARENT, 24));

        // retrieve the top view of our application
        final FrameLayout decorView = (FrameLayout) getWindow().getDecorView();
        decorView.addView(progressBar);

        ViewTreeObserver observer = progressBar.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                View contentView = decorView.findViewById(android.R.id.content);
                progressBar.setY(contentView.getY()-10);
                progressBar.setX(0);

                ViewTreeObserver observer = progressBar.getViewTreeObserver();
                observer.removeGlobalOnLayoutListener(this);
            }
        });

I am referring to this question: ProgressBar under Action Bar

Could you tell me what I have done wrong in the code, or some other way to achieve this.

Community
  • 1
  • 1
Xhulio
  • 571
  • 6
  • 25

1 Answers1

0

Change the offset of Progress Bar using offsetTopAndBottom. See: ProgressBar

sahu
  • 1,375
  • 3
  • 17
  • 25
  • I used in this form `progressBar.offsetTopAndBottom((int)contentView.getY()-10);` and now it doesn't display anything. – Xhulio Oct 12 '15 at 12:06
  • try changing parameter try moving downwards. I think you need to add some value to it. – sahu Oct 12 '15 at 12:14