How to make ProgressBar fit the screen?

0

I'm developing an app for my site and until finally I can add a ProgressBar that accompanies the loading of the page, then get a style and now it only needs that it actually start from the top of the screen (same as Chrome) the blue bar starts from one side to the other, and mine a little cuts the beginning and the end. Here's the layout:

  

main.xml

<ProgressBar
    android:id="@+id/progressBar"
    android:minHeight="2dip"
    android:maxHeight="3dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_alignParentTop="true" />
<WebView
    android:id="@+id/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/progressBar" />

  

style.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="CustomProgressBar" parent="android:Widget.ProgressBar.Horizontal">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/custom_progress_bar_horizontal</item>
    <item name="android:minHeight">0dip</item>
    <item name="android:maxHeight">0dip</item>
</style>

  

custom_progress_bar_horizontal.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@android:id/background">
        <shape>
            <corners
                android:radius="5dip" />
            <gradient
                android:startColor="#ffffffff"
                android:centerColor="#ffdddddd"
                android:centerY="0.50"
                android:endColor="#ffffffff"
                android:angle="270" />
        </shape>
    </item>
    <item
        android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners
                    android:radius="0dip" />
                <gradient
                    android:startColor="#770e75af"
                    android:endColor="#771997e1"
                    android:angle="90" />
            </shape>
        </clip>
    </item>
    <item
        android:id="@android:id/progress">
        <clip>
            <shape>
                <corners
                    android:radius="5dip" />
                <gradient
                    android:startColor="#212121"
                    android:endColor="#000000"
                    android:angle="90" />
            </shape>
        </clip>
    </item>
</layer-list>
  

MainActivity.java

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

    private ProgressBar progressBar;
    private WebView webView;
    @SuppressLint("SetJavaScriptEnabled")

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        progressBar.setMax(100);

        progressBar.setProgressDrawable(getResources().getDrawable(R.drawable.custom_progress_bar_horizontal));

        webView = (WebView) findViewById(R.id.webView);
        webView.setWebViewClient(new WebViewClientDemo());
        webView.setWebChromeClient(new WebChromeClientDemo());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.techpositivo.com.br");

    }

    private class WebViewClientDemo extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
    }
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            progressBar.setProgress(100);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(0);
        }
    }

    private class WebChromeClientDemo extends WebChromeClient {
        public void onProgressChanged(WebView view, int progress) {
            progressBar.setProgress(progress);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        else {
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return true;
    }
}

Thank you very much, I hope you guys help me, because I'm starting programming. ;)

    
asked by anonymous 03.02.2016 / 16:50

0 answers