Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity.setProgress(int progress) is deprecated

I would like to show progress bar when android webview is loading and I used Activity.setProgess(int).

Android documentation says setProgress(int progress) was deprecated in API level 24. No longer supported starting in API 21.

So, what should I use instead to show progress when webview is loading?

like image 485
BomberBus Avatar asked Aug 09 '16 07:08

BomberBus


1 Answers

Implement toolbar with progress bar or spinner.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_actionbar"
    style="@style/HeaderBar"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:visibility="visible"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/ActionBarPopupThemeOverlay"
    app:theme="@style/ActionBarThemeOverlay"
    >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:gravity="right"
        android:divider="?android:dividerVertical"
        android:dividerPadding="8dp"
        android:orientation="horizontal"
        android:showDividers="beginning|middle">

        <ProgressBar
            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
            android:id="@+id/toolbarProgressBar"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"/>
    </RelativeLayout>
</android.support.v7.widget.Toolbar>

Then find it in your view and update.

ProgressBar progressBar = (ProgressBar)findViewById(R.id.toolbarProgressBar);  
progressBar.setIndeterminate(false);
progressBar.setProgress(x);
like image 146
shtolik Avatar answered Oct 31 '22 10:10

shtolik