Has the onKeyDown
Class MainActivity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void teste(View view) {
Intent i = new Intent(this, Teste.class);
startActivity(i);
}
}
You will call the método
"test" by botão
in his MainActivity
Class Teste:
public class Teste extends AppCompatActivity {
private WebView wv;
private WebSettings ws;
private WebViewClient wc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_teste);
this.wv = (WebView) findViewById(R.id.webViewTeste);
this.wc = new WebViewClient();
this.ws = this.wv.getSettings();
this.ws.setJavaScriptEnabled(true);
this.ws.setSupportZoom(true);
this.ws.setBuiltInZoomControls(true);
this.ws.setDisplayZoomControls(false);
this.wv.setWebViewClient(wc);
wv.loadUrl("http://www.seusite.com.br");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && wv != null && wv.canGoBack()) {
wv.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#e6ee9c"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="com.susite.app.MainActivity"
android:weightSum="1">
<Button
android:id="@+id/btnEntrar"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:onClick="teste"
android:text="entrar" />
</LinearLayout>
activity_teste.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.seusite.app">
<WebView
android:id="@+id/webViewTeste"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Answer containing only link are not very interesting, could put a minimum use example?
– Don't Panic