Skip to content

Instantly share code, notes, and snippets.

@skryshtafovych
Last active March 1, 2019 19:49
Show Gist options
  • Save skryshtafovych/f37b9aafccb356282179284f2197c6a2 to your computer and use it in GitHub Desktop.
Save skryshtafovych/f37b9aafccb356282179284f2197c6a2 to your computer and use it in GitHub Desktop.
Stack Answer
package web.view.expirement;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Context cn = getBaseContext();
WebView wv = findViewById(R.id.myWebView);
wv.loadUrl("https://www.blogmaza.com/");
wv.getSettings().setSupportMultipleWindows(true);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("URLOFCLICK"+url);
Intent intents=new Intent(cn,WebviewOpenerLikeGMAIL.class);
intents.putExtra("URL", url);
startActivity(intents);
return true;
}
});
}
}
================================================Another File
public class WebviewOpenerLikeGMAIL extends Activity implements Serializable, View.OnClickListener {
private WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gmaillike);
mWebView = findViewById(R.id.myGMAILwebview);
Button closeVIEW = findViewById(R.id.button);
closeVIEW.setOnClickListener(this);
String value = getIntent().getExtras().getString("URL");
mWebView.loadUrl(value);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
}
@Override
public void onClick(View v) {
onBackPressed();
}
@Override
public void onBackPressed() {
//this is only needed if you have specific things
//that you want to do when the user presses the back button.
/* your specific things...*/
super.onBackPressed();
}
}
GMAIL LookALIKE VIEW XML Another FILE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CLOSE" />
<WebView
android:id="@+id/myGMAILwebview"
android:layout_width="match_parent"
android:layout_height="400dp" />
</LinearLayout>
MAIN ACTIVITY VIEW XML Another File
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView
android:id="@+id/myWebView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment