strong textHi I'm 15 and I'm trying to make a web browser please I'm having problems showing the current url in edit text for example in chrome when you type a webpage you it shows a redirect url in editText please here is my code help me I really need this for a school project please I need your help
package com.razormist.simplewebviewer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.content.*;
import android.view.inputmethod.*;
import android.widget.*;
import android.webkit.*;
import org.apache.http.*;
import java.net.*;
import android.net.*;
import android.util.*;
import org.apache.http.impl.cookie.*;
import android.widget.TextView.*;
import android.view.*;
import android.text.*;
public class MainActivity extends AppCompatActivity {
private EditText et_url;
private ImageButton homeButton,reload,forword;
private WebView wv_browser;
private ProgressBar progress_bar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SearchSite();
wv_browser.getSettings().setBuiltInZoomControls(true);
}
public void SearchSite(){
et_url = (EditText)findViewById(R.id.et_url);
wv_browser = (WebView)findViewById(R.id.wv_browser);
progress_bar = (ProgressBar) findViewById(R.id.progress_bar);
homeButton = (ImageButton) findViewById(R.id.home);
reload = (ImageButton) findViewById(R.id.reload);
forword = (ImageButton) findViewById(R.id.forword);
progress_bar.setMax(100);
progress_bar.setVisibility(View.GONE);
et_url.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
String url = "https://" + et_url.getText().toString();
wv_browser.getSettings().setLoadsImagesAutomatically(true);
wv_browser.getSettings().setJavaScriptEnabled(true);
wv_browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv_browser.setWebViewClient(new WebViewClient());
wv_browser.loadUrl(url);
return true;
}
return false;
}
});
wv_browser.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
progress_bar.setProgress(newProgress);
if (newProgress < 100 && progress_bar.getVisibility() == ProgressBar.GONE) {
progress_bar.setVisibility(ProgressBar.VISIBLE);
}
if (newProgress == 100) {
progress_bar.setVisibility(ProgressBar.GONE);
}else{
progress_bar.setVisibility(ProgressBar.VISIBLE);
}
}
});
homeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wv_browser.getSettings().setLoadsImagesAutomatically(true);
wv_browser.getSettings().setJavaScriptEnabled(true);
wv_browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv_browser.setWebViewClient(new WebViewClient());
;
wv_browser.loadUrl("https://techpord2.blogspot.com");
et_url.setText("");
}
});
forword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (wv_browser.canGoForward()) {
wv_browser.goForward();
}
}
});
reload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wv_browser.reload();
}
});
}
@Override
public void onBackPressed() {
if (wv_browser.canGoBack()) {
wv_browser.goBack();
} else {
super.onBackPressed();
}
}
}
Aucun commentaire:
Enregistrer un commentaire