Java Code Examples for android.webkit.WebView#setBackgroundColor()

The following examples show how to use android.webkit.WebView#setBackgroundColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AboutActivity.java    From MuslimMateAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);

    getSupportActionBar().setTitle(getString(R.string.about));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    progressBar = (ProgressBar) findViewById(R.id.progress);
    progressBar.getIndeterminateDrawable()
            .setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
    info_web = (WebView) findViewById(R.id.webview_company_info);
    info_web.setBackgroundColor(Color.TRANSPARENT);
    info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    info_web.setWebViewClient(new myWebClient());
    info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    info_web.getSettings().setJavaScriptEnabled(true);
    info_web.getSettings().setDefaultFontSize((int) getResources().getDimension(R.dimen.about_text_size));

    String infoText = getString(R.string.company_info_web);
    info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null);

}
 
Example 2
Source File: LicenseAgreementActivity.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void viewGoogleLicenses(View myview) {
    try {
        if (!appended) {
            final String googleLicense = GoogleApiAvailability.getInstance().getOpenSourceSoftwareLicenseInfo(getApplicationContext());
            if (googleLicense != null) {
                String whiteheader = "<font size=-2 color=white><pre>";
                String whitefooter = "</font></pre>";
                WebView textview = (WebView) findViewById(R.id.webView);
                textview.setBackgroundColor(Color.TRANSPARENT);
                textview.getSettings().setJavaScriptEnabled(false);
                textview.loadDataWithBaseURL("", whiteheader + googleLicense + whitefooter, "text/html", "UTF-8", "");
                appended = true;
                findViewById(R.id.googlelicenses).setVisibility(View.INVISIBLE);
                findViewById(R.id.webView).setVisibility(View.VISIBLE);

            } else {
                UserError.Log.d(TAG, "Nullpointer getting Google License: errorcode:" + GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getApplicationContext()));
                findViewById(R.id.googlelicenses).setVisibility(View.INVISIBLE);
            }
        }
    } catch (Exception e) {
        // meh
    }
}
 
Example 3
Source File: DisplayHtmlFragment.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final void onActivityCreated(final Bundle savedInstanceState) {
	super.onActivityCreated(savedInstanceState);
	if (getView() == null) {
		return;
	}

	WebView webView = getView().findViewById(R.id.webViewDisplayHtml);
	webView.setBackgroundColor(0x00000000);

	setOpenLinksInExternalBrowser(webView);

	String html = getString(mResource);
	if (mResource == R.string.html_release_notes_base) {
		int indexBody = html.indexOf("</body>");
		String releaseNotes =
				ReleaseNotesUtil.getReleaseNotesHtml(getActivity(), false, 1, Application.getVersion());
		html = html.substring(0, indexBody) + releaseNotes + html.substring(indexBody);
	}

	// add style
	int index = html.indexOf("</head>");
	html = html.substring(0, index) + STYLE + html.substring(index);

	webView.loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html", "utf-8", "");
}
 
Example 4
Source File: LicenseAgreementActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void viewGoogleLicenses(View myview) {
    try {
        if (!appended) {
            final String googleLicense = GoogleApiAvailability.getInstance().getOpenSourceSoftwareLicenseInfo(getApplicationContext());
            if (googleLicense != null) {
                String whiteheader = "<font size=-2 color=white><pre>";
                String whitefooter = "</font></pre>";
                WebView textview = (WebView) findViewById(R.id.webView);
                textview.setBackgroundColor(Color.TRANSPARENT);
                textview.getSettings().setJavaScriptEnabled(false);
                textview.loadDataWithBaseURL("", whiteheader + googleLicense + whitefooter, "text/html", "UTF-8", "");
                appended = true;
                findViewById(R.id.googlelicenses).setVisibility(View.INVISIBLE);
                findViewById(R.id.webView).setVisibility(View.VISIBLE);

            } else {
                UserError.Log.d(TAG, "Nullpointer getting Google License: errorcode:" + GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getApplicationContext()));
                findViewById(R.id.googlelicenses).setVisibility(View.INVISIBLE);
            }
        }
    } catch (Exception e) {
        // meh
    }
}
 
Example 5
Source File: MainHelpActivity.java    From Bluefruit_LE_Connect_Android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mainhelp);

    TextView versionTextView = (TextView) findViewById(R.id.versionTextView);
    if (versionTextView != null) {
        versionTextView.setText("v" + BuildConfig.VERSION_NAME);
    }

    WebView infoWebView = (WebView) findViewById(R.id.infoWebView);
    if (infoWebView != null) {
        infoWebView.setBackgroundColor(Color.TRANSPARENT);
        infoWebView.loadUrl("file:///android_asset/help/app_help.html");
    }
}
 
Example 6
Source File: IncomingMessageViewHolder.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
public IncomingMessageViewHolder(View itemView) {
    super(itemView);

    attachmentsContainer = itemView.findViewById(R.id.attachmentsContainer);
    senderName = itemView.findViewById(R.id.senderName);
    selectedBubble = itemView.findViewById(R.id.selectedMessageBubble);
    replayButton = itemView.findViewById(R.id.replayButton);

    WebView invisibleInkView = new WebView(getActivity());
    invisibleInkView.getSettings().setJavaScriptEnabled(true);
    invisibleInkView.setBackgroundColor(Color.TRANSPARENT);
    invisibleInkView.addJavascriptInterface(this, "weMessage");
    invisibleInkView.setVerticalScrollBarEnabled(false);
    invisibleInkView.setHorizontalScrollBarEnabled(false);

    bubble.addView(invisibleInkView);
    this.invisibleInkView = invisibleInkView;
}
 
Example 7
Source File: EmoticsQuickView.java    From 4pdaClient-plus with Apache License 2.0 5 votes vote down vote up
@Override
View createView() {
    if (getContext() == null)
        return new View(getContext());
    LayoutInflater inflater = LayoutInflater.from(getContext());
    webView = new WebView(inflater.getContext());
    webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    webView.setBackgroundColor(AppTheme.getThemeStyleWebViewBackground());
    loadWebView();
    return webView;
}
 
Example 8
Source File: Utils.java    From uservoice-android-sdk with MIT License 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
public static void displayArticle(WebView webView, Article article, Context context) {
    String styles = "iframe, img { max-width: 100%; }";
    if (isDarkTheme(context)) {
        webView.setBackgroundColor(Color.parseColor("#303030"));
        styles += "body { background-color: #303030; color: #F6F6F6; } a { color: #0099FF; }";
    }
    String html = String.format("<html><head><meta charset=\"utf-8\"><link rel=\"stylesheet\" type=\"text/css\" href=\"http://cdn.uservoice.com/stylesheets/vendor/typeset.css\"/><style>%s</style></head><body class=\"typeset\" style=\"font-family: sans-serif; margin: 1em\"><h3>%s</h3><br>%s</body></html>", styles, article.getTitle(), article.getHtml());
    webView.setWebChromeClient(new WebChromeClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.loadUrl(String.format("data:text/html;charset=utf-8,%s", Uri.encode(html)));
}
 
Example 9
Source File: MainActivity.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
@Override
public void onProgressChanged(WebView view, int progress) {
    mProgress.setProgress(progress);
    if (progress < 100) {
        mProgress.setVisibility(View.VISIBLE);
    } else {
        mProgress.setVisibility(GONE);
    }
    if (UserPreferences.getBoolean("dark_mode_web", false) && view != null) {
        CSSInjection.injectDarkMode(SimplicityApplication.getContextOfApplication(), view);
        view.setBackgroundColor(Color.parseColor("#202020"));
    }
    super.onProgressChanged(view, progress);
}
 
Example 10
Source File: AboutDialog.java    From UpdogFarmer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final WebView webView = (WebView) LayoutInflater.from(getActivity()).inflate(R.layout.about_dialog, null);
    final String lang = Locale.getDefault().getLanguage();
    String uri = "file:///android_asset/about.html";
    try {
        // Load language-specific version of the about page if available.
        final List<String> assets = Arrays.asList(getResources().getAssets().list(""));
        if (assets.contains(String.format("about-%s.html", lang))) {
            uri = String.format("file:///android_asset/about-%s.html", lang);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        // Getting Chromium crashes on certain KitKat devices. Might be caused by hardware acceleration
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    webView.loadUrl(uri);
    webView.setBackgroundColor(Color.TRANSPARENT);
    return new AlertDialog.Builder(getActivity())
            .setTitle(R.string.about)
            .setView(webView)
            .setPositiveButton(R.string.ok, null)
            .create();
}
 
Example 11
Source File: PKDialog.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private void c()
{
    m = new a((Context)o.get());
    m.setBackgroundColor(0x66000000);
    m.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-1, -1));
    n = new WebView((Context)o.get());
    n.setBackgroundColor(0);
    n.setBackgroundDrawable(null);
    android.widget.RelativeLayout.LayoutParams layoutparams;
    if (android.os.Build.VERSION.SDK_INT >= 11)
    {
        try
        {
            Class aclass[] = new Class[2];
            aclass[0] = Integer.TYPE;
            aclass[1] = android/graphics/Paint;
            Method method = android/view/View.getMethod("setLayerType", aclass);
            WebView webview = n;
            Object aobj[] = new Object[2];
            aobj[0] = Integer.valueOf(1);
            aobj[1] = new Paint();
            method.invoke(webview, aobj);
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
    }
    layoutparams = new android.widget.RelativeLayout.LayoutParams(-1, p);
    layoutparams.addRule(13, -1);
    n.setLayoutParams(layoutparams);
    m.addView(n);
    m.a(this);
    setContentView(m);
}
 
Example 12
Source File: TurbolinksView.java    From turbolinks-android with MIT License 5 votes vote down vote up
/**
 * <p>Attach the swipeRefreshLayout, which contains the shared webView, to the TurbolinksView.</p>
 *
 * @param webView              The shared webView.
 * @param screenshotsEnabled   Indicates whether screenshots are enabled for the current session.
 * @param pullToRefreshEnabled Indicates whether pull to refresh is enabled for the current session.
 * @return True if the webView has been attached to a new parent, otherwise false
 */
boolean attachWebView(WebView webView, boolean screenshotsEnabled, boolean pullToRefreshEnabled) {
    if (webView.getParent() == refreshLayout) return false;

    refreshLayout.setEnabled(pullToRefreshEnabled);

    if (webView.getParent() instanceof TurbolinksSwipeRefreshLayout) {
        TurbolinksSwipeRefreshLayout previousRefreshLayout = (TurbolinksSwipeRefreshLayout) webView.getParent();
        TurbolinksView previousTurbolinksView = (TurbolinksView) previousRefreshLayout.getParent();

        if (screenshotsEnabled) previousTurbolinksView.screenshotView();

        try {
            // This is an admittedly hacky workaround, but it buys us some time as we investigate
            // a potential bug with Chrome 64, which is currently throwing an IllegalStateException
            // when accessibility services (like Talkback or 1password) are enabled.
            // We're tracking this bug on the Chromium issue tracker:
            // https://bugs.chromium.org/p/chromium/issues/detail?id=806108
            previousRefreshLayout.removeView(webView);
        } catch (Exception e) {
            previousRefreshLayout.removeView(webView);
        }
    }

    // Set the webview background to match the container background
    if (getBackground() instanceof ColorDrawable) {
        webView.setBackgroundColor(((ColorDrawable) getBackground()).getColor());
    }

    refreshLayout.addView(webView);
    return true;
}
 
Example 13
Source File: LoginActivity.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private void c()
{
    WebView webview = (WebView)findViewById(0x7f0a003b);
    WebSettings websettings = webview.getSettings();
    websettings.setUseWideViewPort(true);
    websettings.setLoadWithOverviewMode(true);
    webview.setLayerType(1, null);
    webview.setBackgroundColor(0);
    webview.setInitialScale((100 * getResources().getDisplayMetrics().densityDpi) / 480);
    webview.loadUrl("file:///android_asset/startup.gif");
    (new Handler()).postDelayed(new b(this), 4800L);
    C.setEnabled(false);
    r.setEnabled(false);
    s.setEnabled(false);
}
 
Example 14
Source File: NewsDetileActivity.java    From NBAPlus with Apache License 2.0 5 votes vote down vote up
@Override
protected void initViews() {
    super.initViews();
    mGetIntent=getIntent();
    if(hasTitleImage()) {

        mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
        mCollapsingToolbarLayout.setTitle(mGetIntent.getStringExtra(TITLE));
        mTitleImage = (ImageView)findViewById(R.id.titleImage);
        mTitleImage.post(new Runnable() {
            @Override
            public void run() {
                Glide.with(NewsDetileActivity.this).load(mGetIntent.getStringExtra(IMAGE_URL))
                .placeholder(R.color.colorPrimary)
                .into(mTitleImage);
            }
        });

    } else {
        mToolBar.setBackgroundResource(R.color.colorPrimary);

    }
    mWebView = new WebView(getApplicationContext());
    mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setBackgroundColor(0);
    mWebLayout.addView(mWebView);

    getNewsDetail();
}
 
Example 15
Source File: WebInitCompat.java    From Android_Skin_2.0 with Apache License 2.0 5 votes vote down vote up
@Override
public void setDefaultAttr(WebView view) {
	// 去除滚动条白色背景,必须在代码里面添加才有效
	view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
	view.setScrollbarFadingEnabled(true);
	view.setDrawingCacheEnabled(true);
	view.setLongClickable(true);
	view.setBackgroundResource(android.R.color.transparent);
	view.setBackgroundColor(Color.TRANSPARENT);
	view.getBackground().setAlpha(0);
	view.setFocusable(true);
	view.setFocusableInTouchMode(true);
}
 
Example 16
Source File: Utils.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
public static void displayArticle(WebView webView, Article article, Context context) {
    String styles = "iframe, img { width: 100%; }";
    if (isDarkTheme(context)) {
        webView.setBackgroundColor(Color.BLACK);
        styles += "body { background-color: #000000; color: #F6F6F6; } a { color: #0099FF; }";
    }
    String html = String.format("<html><head><meta charset=\"utf-8\"><link rel=\"stylesheet\" type=\"text/css\" href=\"http://cdn.uservoice.com/stylesheets/vendor/typeset.css\"/><style>%s</style></head><body class=\"typeset\" style=\"font-family: sans-serif; margin: 1em\"><h3>%s</h3>%s</body></html>", styles, article.getTitle(), article.getHtml());
    webView.setWebChromeClient(new WebChromeClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.loadUrl(String.format("data:text/html;charset=utf-8,%s", Uri.encode(html)));
}
 
Example 17
Source File: LargePictureFragment.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.gallery_large_layout, container, false);

    final WebView large = (WebView) view.findViewById(R.id.large);
    large.setBackgroundColor(getResources().getColor(R.color.transparent));
    large.setVisibility(View.INVISIBLE);
    large.setOverScrollMode(View.OVER_SCROLL_NEVER);

    if (SettingUtils.allowClickToCloseGallery()) {
        large.setOnTouchListener(new LargeOnTouchListener(large));
    }

    LongClickListener longClickListener = ((BigPicContainerFragment) getParentFragment()).getLongClickListener();
    large.setOnLongClickListener(longClickListener);

    final String path = getArguments().getString("path");

    large.getSettings().setJavaScriptEnabled(true);
    large.getSettings().setUseWideViewPort(true);
    large.getSettings().setLoadWithOverviewMode(true);
    large.getSettings().setBuiltInZoomControls(true);
    large.getSettings().setDisplayZoomControls(false);

    large.setVerticalScrollBarEnabled(false);
    large.setHorizontalScrollBarEnabled(false);
    large.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    boolean animateIn = getArguments().getBoolean("animationIn");

    if (animateIn) {
        showContent(path, large);
    } else {
        /**
         * webview will influence other imageview animation performance
         */
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                showContent(path, large);
            }
        }, GeneralPictureFragment.ANIMATION_DURATION + 300);
    }

    return view;
}
 
Example 18
Source File: QuestionnaireView.java    From QuestionnaireView with MIT License 4 votes vote down vote up
private void drawInnerViews(Context context, AttributeSet attrs){
    float density = context.getResources().getDisplayMetrics().density;
    int value16 = (int)(16*density);
    int value10 = (int)(10*density);
    int value40 = (int)(40*density);
    LayoutParams mainLayoutParams = new LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mainLayoutParams.setMargins(value16,value16,value16,value16);
    setLayoutParams(mainLayoutParams);

    //creation & addition of webview
    webview = new WebView(context, attrs);
    webview.setId(android.R.id.content);
    webview.setLayoutParams(
            new LayoutBuilder()
                    .addWidth(LayoutParams.MATCH_PARENT)
                    .addHeight(LayoutParams.WRAP_CONTENT)
                    .setMargin(value10,value40,0,0)
                    .create()
    );
    webview.getSettings();
    webview.setBackgroundColor(Color.argb(0,0,0,0));
    addView(webview);

    //creation of list view
    listView = new ListView(context, attrs);
    listView.setId(android.R.id.list);
    listView.setLayoutParams(
            new LayoutBuilder()
                    .addWidth(LayoutParams.MATCH_PARENT)
                    .addHeight(LayoutParams.WRAP_CONTENT)
                    .setMargin(0,value10,0,0)
                    .addRule(BELOW, webview.getId() )
                    .create()
    );
    addView(listView );

    //creation & addition of editText
    editTv = new AppCompatEditText(context, attrs);
    editTv.setVisibility(GONE);
    editTv.setId(android.R.id.text1);
    editTv.setLayoutParams(
            new LayoutBuilder()
                    .addWidth(LayoutParams.MATCH_PARENT)
                    .addHeight(LayoutParams.WRAP_CONTENT)
                    .setMargin(value10, value10, 0, 0)
                    .addRule(BELOW, webview.getId())
                    .create()
    );
    editTv.setInputType(InputType.TYPE_CLASS_TEXT);
    editTv.setImeOptions(EditorInfo.IME_ACTION_DONE);
    addView(editTv );

}
 
Example 19
Source File: WebPlayerView.java    From mv-android-client with Apache License 2.0 4 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    super.onReceivedError(view, request, error);
    view.setBackgroundColor(Color.WHITE);
}