-1
- This is my code Mainactivity.java when running on a device I click the back button simply appears the message Launcher stopped
I really need to understand what is missing in the code my main concept of error is everywhere in (keycode == Keyevent.KEYCODE_BACK && webView.canGoBack())
public class MainActivity extends AppCompatActivity {
private Object WebResourceRequest;
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressBar progressBar = findViewById(R.id.progress);
progressBar.setVisibility(View.INVISIBLE);
WebView webView = findViewById(R.id.webview);
webView.loadUrl("https://oolze.com.br/");
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE); // mostra a progress
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.INVISIBLE); // esconde a progress
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
My activity_main.xml Here’s the Activity xml where the webview and progress bar are
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
Very obg, gave certoooooo !!! was breaking his head because of a line of code kkkk
– wall code
If the answer served, mark it as accepted. See on tour how to do.
– Piovezan