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.
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.