Example usage for android.webkit WebView setBackgroundColor

List of usage examples for android.webkit WebView setBackgroundColor

Introduction

In this page you can find the example usage for android.webkit WebView setBackgroundColor.

Prototype

@Override
    public void setBackgroundColor(int color) 

Source Link

Usage

From source file:Main.java

/**
 * Set a transparent background to a WebView
 *
 * @param webView the WebView with a default background
 *//*from www . ja  v  a 2 s. c o  m*/
public static void setWebViewTransparentBackground(WebView webView) {

    if (android.os.Build.VERSION.SDK_INT < 16) {
        webView.setBackgroundColor(0x00000000);
    } else {
        webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
    }
}

From source file:net.naonedbus.utils.InfoDialogUtils.java

/**
 * Afficher une dialog avec un contenu au format HTML
 * //from  ww w .  j  a v a  2  s.  co  m
 * @param context
 * @param html
 */
public static void showHtml(final Context context, final String html) {
    AlertDialog.Builder moreDetailsDialog = null;
    final WebView webView = new WebView(context);
    final ScrollView scrollView = new ScrollView(context);

    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.setBackgroundColor(Color.WHITE);
    webView.loadDataWithBaseURL("fake://not/needed", html, "text/html", "UTF-8", null); // Encoding
    // fix
    // for
    // Android
    // 3.x
    // /
    // 4.x
    scrollView.addView(webView);

    moreDetailsDialog = new AlertDialog.Builder(context);
    moreDetailsDialog.setIcon(android.R.drawable.ic_dialog_info);
    moreDetailsDialog.setTitle("Informations");
    moreDetailsDialog.setView(scrollView);
    moreDetailsDialog.setPositiveButton(android.R.string.ok, null);
    moreDetailsDialog.show();
}

From source file:org.microg.gms.auth.login.LoginActivity.java

private static WebView createWebView(Context context) {
    WebView webView = new WebView(context);
    if (SDK_INT < LOLLIPOP) {
        webView.setVisibility(VISIBLE);// ww  w  .j a  v a 2  s . c om
    } else {
        webView.setVisibility(INVISIBLE);
    }
    webView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setBackgroundColor(Color.TRANSPARENT);
    prepareWebViewSettings(webView.getSettings());
    return webView;
}

From source file:ca.rmen.android.networkmonitor.app.speedtest.SpeedTestAboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.v(TAG, "onCreateView");
    View rootView = inflater.inflate(R.layout.fragment_speed_test_about, container, false);
    WebView wv = (WebView) rootView.findViewById(R.id.webview);
    wv.setBackgroundColor(0);
    wv.getSettings().setDefaultFontSize(14);
    wv.loadUrl(getString(R.string.speed_test_about_file));
    return rootView;
}

From source file:net.naonedbus.fragment.impl.WebViewFragment.java

@Override
protected void bindView(final View view, final Bundle savedInstanceState) {
    try {/*from w w  w .j  av  a2s  . com*/
        final WebView wv = (WebView) view.findViewById(R.id.webView);
        wv.setBackgroundColor(getResources().getColor(R.color.activity_background_light));

        final int rawId = getArguments().getInt(PARAM_RAW_ID);

        final String content = IOUtils.toString(getResources().openRawResource(rawId), ENCODING);
        // Problme d'encodage avec le loadData.
        wv.loadDataWithBaseURL("fake://not/needed", content, "text/html", ENCODING, "");
    } catch (final NotFoundException e) {
        Log.e(LOG_TAG, "Erreur de chargement des notes de versions", e);
    } catch (final IOException e) {
        Log.e(LOG_TAG, "Erreur de chargement des notes de versions", e);
    }
}

From source file:net.naonedbus.fragment.impl.VersionsFragment.java

@Override
protected void bindView(final View view, final Bundle savedInstanceState) {
    try {//from   w w  w. j  a  va  2 s. c om
        final WebView wv = (WebView) view.findViewById(R.id.webView);
        wv.setBackgroundColor(getResources().getColor(R.color.activity_background_light));
        final String content = IOUtils.toString(getResources().openRawResource(R.raw.version), ENCODING);
        // Problme d'encodage avec le loadData.
        wv.loadDataWithBaseURL("fake://not/needed", content, "text/html", ENCODING, "");
    } catch (final NotFoundException e) {
        Log.e(LOG_TAG, "Erreur de chargement des notes de versions", e);
    } catch (final IOException e) {
        Log.e(LOG_TAG, "Erreur de chargement des notes de versions", e);
    }

    // if (mUpgradeError) {
    // InfoDialogUtils.show(this, R.string.error_title_upgrade,
    // R.string.error_summary_upgrade);
    // }
}

From source file:se.eliga.aves.HelpFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    WebView webView = (WebView) getView().findViewById(R.id.help_text);
    webView.loadUrl("file:///android_asset/help.html");
    webView.setBackgroundColor(0x00FFFFFF);
    webView.setVisibility(View.VISIBLE);
}

From source file:io.github.hidroh.materialistic.OfflineWebActivity.java

@SuppressWarnings("ConstantConditions")
@Override//from ww  w . j  a va  2s.c  om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String url = getIntent().getStringExtra(EXTRA_URL);
    if (TextUtils.isEmpty(url)) {
        finish();
        return;
    }
    setTitle(url);
    setContentView(R.layout.activity_offline_web);
    final NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.nested_scroll_view);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setOnClickListener(v -> scrollView.smoothScrollTo(0, 0));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayOptions(
            ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    getSupportActionBar().setSubtitle(R.string.offline);
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress);
    final WebView webView = (WebView) findViewById(R.id.web_view);
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(this)) {
        @Override
        public void onPageFinished(WebView view, String url) {
            setTitle(view.getTitle());
        }
    });
    webView.setWebChromeClient(new CacheableWebView.ArchiveClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(newProgress);
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
                webView.setBackgroundColor(Color.WHITE);
                webView.setVisibility(View.VISIBLE);
            }
        }
    });
    AppUtils.toggleWebViewZoom(webView.getSettings(), true);
    webView.loadUrl(url);
}

From source file:justforcommunity.radiocom.fragments.HomePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_home, container, false);

    mActivity = (Home) getActivity();//from   w  w  w .j a va  2 s .  c  o  m
    mContext = getContext();

    try {
        station.getHistory().replace("<body",
                "<body style=\'text-align:justify;color:gray;background-color:black;\'");
        station.getHistory().replaceAll("style=\".+?\"", "");

    } catch (Exception e) {

    }

    WebView wb = (WebView) v.findViewById(R.id.history_frame);
    wb.setBackgroundColor(Color.WHITE);

    // String fontscript = "<style>@font-face {font-family : 'HelveticaNeue-Light';src:url('file:///android_asset/fonts/"+VariablesGlobalesActivity.GENERICFONT+"');}</style>";
    String fontscript = "";
    String script = "<style type='text/css' >p{width:100%;}img{width:100%;height:auto;-webkit-transform: translate3d(0px,0px,0px);}a,h1,h2,h3,h4,h5,h6{color:"
            + GlobalValues.colorHTML
            + ";}div,p,span,a {max-width: 100%;}iframe{width:100%;height:auto;}</style>";

    wb.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    });

    wb.loadDataWithBaseURL("",
            "<html><head>" + fontscript + script + "</head><body style=\"font-family:HelveticaNeue-Light; \">"
                    + station.getHistory() + "</body></html>",
            "text/html", "utf-8", "");

    wb.getSettings().setDomStorageEnabled(true);
    wb.getSettings().setJavaScriptEnabled(true);

    App application = (App) getActivity().getApplication();
    Tracker mTracker = application.getDefaultTracker();
    mTracker.setScreenName(getString(R.string.home_view));
    mTracker.send(new HitBuilders.ScreenViewBuilder().build());

    return v;
}

From source file:se.eliga.aves.AboutFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    WebView webView = (WebView) getView().findViewById(R.id.about_text);
    webView.loadUrl("file:///android_asset/about.html");
    webView.setBackgroundColor(0x00FFFFFF);
    webView.setVisibility(View.VISIBLE);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webView.addJavascriptInterface(/*from www .j  a v a  2  s. c om*/
            new AboutJSObject(getVersion(), BuildConfig.BUILDTIME, BuildConfig.BUILDTYPE), "AboutData");
}