Created
February 8, 2015 18:26
-
-
Save easyaspi314/aaffea99461139077389 to your computer and use it in GitHub Desktop.
Android WebView code that works with Facebook's image scaling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="#ffff" > | |
<WebView | |
android:id="@+id/webView" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.facebookwebview; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.webkit.WebView; | |
import android.webkit.WebViewClient; | |
import com.example.facebookwebview.R; | |
import android.view.Window; | |
public class MainActivity extends Activity | |
{ | |
private WebView webView; | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
getWindow().requestFeature(Window.FEATURE_NO_TITLE); | |
setContentView(R.layout.main); | |
webView = (WebView) findViewById(R.id.webView); | |
webView.getSettings().setAllowFileAccess(true); | |
webView.getSettings().setAppCacheEnabled(true); | |
webView.setWebViewClient(new MyBrowser()); | |
String url = "http://m.facebook.com/"; | |
webView.getSettings().setLoadsImagesAutomatically(true); | |
webView.getSettings().setJavaScriptEnabled(true); | |
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); | |
webView.getSettings().setLoadWithOverviewMode(true); | |
webView.getSettings().setUseWideViewPort(true); | |
webView.loadUrl(url); | |
} | |
private class MyBrowser extends WebViewClient | |
{ | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) | |
{ | |
view.loadUrl(url); | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment