MainActivity.java
=================
package com.thistimebd.web.webapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView) findViewById(R.id.webViewId);
WebSettings webSettings=webView.getSettings();
webSettings.setJavaScriptEnabled(true);
//adding back button to the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://www.ox.ac.uk");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==android.R.id.home){
this.finish();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
}else{
super.onBackPressed();
}
}
}
=======================================================================================
android_manifest.xml
====================
Adding Back / Up Button To Toolbar
====================================
<activity android:name=".TutorialActivity"
android:parentActivity_main=".MainActivity">
</activity>
thistimebd Bangladesh Live online newsportal, education, Lifestyle, Health, Photography, gif image etc.
Make your own name or company name website | contact: thistimebd24@gmail.com
Copyright © 2020-2024 News Portal in Bangladesh - THISTIMEBD.COM. ALL Rights Reserved.