Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing a progressBar in a popup

Tags:

android

I have a popup dialog box in which I am loading a webview. I want to show a progressBar while the webview is loading on top of the popup window. I have found a way to show loading progressbar while the webpage loads but if this webview is loading in the popup dialog box the progressBar is not shown on top of it. Can someone explain the reason why this is happening.

Here is the code

[code]

 @SuppressWarnings("static-access")
    public void showPopUp(String url){
            try{

                Dialog dialog = new Dialog(Links.this);
                LayoutInflater inflater = (LayoutInflater)getSystemService(Links.this.LAYOUT_INFLATER_SERVICE);
                View vi = inflater.inflate(R.layout.link_popup, null);
                dialog.setContentView(vi);
                dialog.setTitle("Title here");
                dialog.setCancelable(true);
                WebView wb = (WebView) vi.findViewById(R.id.WebView01);

                wb.setWebViewClient(new MyWebViewClient());
                wb.getSettings().setJavaScriptEnabled(true);   
                wb.getSettings().setSupportZoom(true);      
                wb.loadUrl(url);
//              final Activity MyActivity = this;  
//              
//              progressDialog = ProgressDialog.show(dialog.getOwnerActivity(), "", "Loading....", true);
//              
//              wb.setWebChromeClient(new WebChromeClient() {
//               public void onProgressChanged(WebView view, int progress)   
//               {
//                   MyActivity.setProgress(progress * 100); //Make the bar disappear after URL is loaded
//                   if(progress == 100){
//                    if(progressDialog.isShowing())
//                           progressDialog.dismiss();
//                   }
//                 }
//               }); 

                System.out.println("..loading url..");  
                dialog.show();

             }catch(Exception e){
                 System.out.println("Exception while showing Agreement : " + e.getMessage());
             }
        } 

[/code]

It was not working so I commented it.

link_popup.xml

[code]

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="fill"
android:id="@+id/layout_root"
android:background="#000000"
>

        <ProgressBar

            android:layout_width="fill_parent" 
            android:layout_height="5dip"
            android:layout_alignParentTop="true" 
            style="?android:attr/progressBarStyleHorizontal"
            android:id="@+id/progressbar_Horizontal"
            android:max="100"
            android:background="#228b22"
         />
        <WebView  
            android:id="@+id/WebView01"
            android:layout_below="@id/progressbar_Horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_centerVertical="true"
            android:layout_centerInParent="true"
            android:scrollbars="@null"
          />
</RelativeLayout>

[/code]

like image 768
James Avatar asked Nov 04 '22 11:11

James


1 Answers

I haven't looked at your code, but if you look at the xml, you have a RelativeLayout, a ProgessBar and a WebView.

When this is inflated, it will first draw the RelativeLayout, than your Progessbar, and finally your WebView. Since your webview has fill_parent on the width and height, the ProgressBar will stay behind the WebView...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="fill"
    android:id="@+id/layout_root"
    android:background="#000000">

    <!-- First the WebView -->
    <WebView  
        android:id="@+id/WebView01"
        android:layout_below="@id/progressbar_Horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:scrollbars="@null"
      />

      <!-- Than the Progessbar on top of it -->
      <ProgressBar
        android:layout_width="fill_parent" 
        android:layout_height="5dip"
        android:layout_alignParentTop="true" 
        style="?android:attr/progressBarStyleHorizontal"
        android:id="@+id/progressbar_Horizontal"
        android:max="100"
        android:background="#228b22"
     />
</RelativeLayout>
like image 68
Entreco Avatar answered Nov 15 '22 06:11

Entreco