Text on Progressbar

Asked

Viewed 404 times

0

I’m a beginner in Android, and I’m with a doubt here that for many can be simple, but for me it’s kind of complicated to solve. Ai goes:

I have an app that loads a webview, I put a progressiBar to know if it is opening or not, but I wanted to add a text above or below the written progressibar:

"Wait Carrregando the system"

How do I do that?

Below follows the code of Mainactivity.java and Mainactivity.xml.

Mainactivity.java

package bbacpropaganda.microfapp;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Message;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;




public class MainActivity extends AppCompatActivity {


//Faz a verificacao da conexao com a internet


//Fim da Verificação de conexão com a internet




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView wv = (WebView) findViewById(R.id.webView);
        wv.setWebViewClient(new WebViewClient());
        WebSettings ws= wv.getSettings();
        ws.setJavaScriptEnabled(true);
        ws.setSupportZoom(false);
        //news implementation
        ws.setSaveFormData(true);
        wv.loadUrl("http://sitequevoucarregar.com.br/");
        wv.getSettings().setUseWideViewPort(true);
        wv.getSettings().setLoadWithOverviewMode(true);
        wv.setWebChromeClient(new WebChromeClient());

        //Barra de Progresso / Carregando
        final ProgressBar Pbar;
        Pbar = (ProgressBar) findViewById(R.id.progressBar);


        wv.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                if (progress < 100 && Pbar.getVisibility() == ProgressBar.GONE) {
                    Pbar.setVisibility(ProgressBar.VISIBLE);
                }
                Pbar.setProgress(progress);
                if (progress == 100) {
                    Pbar.setVisibility(ProgressBar.GONE);
                }
            }
        });
        //Fim da Barra de Progresso / Carregando












    }//Final da Classe OnCreate



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
      }
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:name="android.permission.INTERNET"
    tools:context=".MainActivity"
    android:background="#4d9cd6"

      >




    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webView"
        android:layout_alignWithParentIfMissing="true"
        android:clickable="true"
        android:layout_alignParentStart="true" />

    <MediaController
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mediaController"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />

    <ViewAnimator
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/viewAnimator"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true" />

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignWithParentIfMissing="true"
        android:backgroundTint="@android:color/background_dark"
        android:background="@android:color/background_dark"
        android:progressBackgroundTint="#e1ff67" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Carregando"
        android:id="@+id/progressBar"
        android:layout_below="@+id/mediaController"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="231dp" />


</RelativeLayout>

1 answer

1

I see two solutions:

1) You can use a ProgressDialog in this upload. This way you will have a text window above the webview. It is very intuitive for the user.

2) If you wish to do without the ProgressDialog, can use a composition of layout components (RelativeLayout or LinearLayout) to position a TextView above or beside the ProgressBar.

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.