I use this "method" to create the progressbar. It work's until I don't use fragments.
Now I use fragments, a material drawer, and a WebView (of course inside a fragment). I created the progress bar, but it shows in the top of the screen.
Here is my code:
the progress bar:
progressBarLoad = new ProgressBar(getActivity().getBaseContext(), null, android.R.attr.progressBarStyleHorizontal);
progressBarLoad.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 24));
progressBarLoad.setProgress(100);
progressBarLoad.setProgressDrawable(getResources().getDrawable(R.drawable.progress_horizontal_holo_light));
FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView();
decorView.addView(progressBarLoad);
ViewTreeObserver observer = progressBarLoad.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
progressBarLoad.setY(Main.getActionBarSize() + (float) Math.ceil(25 * getResources().getDisplayMetrics().density) - 10);
ViewTreeObserver observer = progressBarLoad.getViewTreeObserver();
observer.removeOnGlobalLayoutListener(this);
}
});
the main layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main.Main">
<android.support.v7.widget.Toolbar
android:id="@+id/Toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/green"
app:popupTheme="@style/Theme.AppCompat"
app:theme="@style/ToolbarTheme" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frameLayout" />
</LinearLayout>
and finally the webView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/SwipeContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/WebViewMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
And here the screenshot:
So, the question is, how can I add this progress bar in to the content screen? Not to the whole device screen.