How to add a progressbar to my application?

0

I have an Activity that calls a method in the oncreate that I created that is called criarlista() . This method creates a ListView loading of an XML, and this process takes about 3.4 seconds because it is loading from an XML.

How do I during that time, run a simple progress bar?

Could someone post an example based on my template?

    
asked by anonymous 27.11.2014 / 23:12

1 answer

0

I have a template in a webview

MainAcitivity

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView myWebView = (WebView) findViewById(R.id.web_engine);

    myWebView.setWebViewClient(new MyBrowser());
    myWebView.clearCache(true);
    myWebView.clearHistory();

    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.getSettings().setLoadsImagesAutomatically(true);
    myWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    myWebView.loadUrl("http://www.mundodamulher.com.br/");
}

private class MyBrowser extends WebViewClient {
    @Override
    public void onPageFinished(WebView view, String url) {
        if (findViewById(R.id.splach_screen).getVisibility() == View.VISIBLE) {
            // show webview
            findViewById(R.id.main_view).setVisibility(View.VISIBLE);
            // hide splash screen
            findViewById(R.id.splach_screen).setVisibility(View.GONE);
        }
    }
}

}

activity_main

<?xml version="1.0" encoding="utf-8"?>

    

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="160dp"
        android:layout_height="10dp"
        android:id="@+id/webViewProgress"
        android:indeterminateOnly="true"
        android:max="100"
        android:indeterminateTint="#e20400"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />


</RelativeLayout>
<LinearLayout
    android:id="@+id/main_view"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="invisible"
    >
    <WebView android:id="@+id/web_engine"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>

I know the color change of the bar works above api 21, still looking for api's bottom

    
24.08.2016 / 20:14