Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6864671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:56:27+00:00 2026-05-27T02:56:27+00:00

I need to know how does the shouldinterceptrequest work. I don’t know how to

  • 0

I need to know how does the shouldinterceptrequest work. I don’t know how to create and handle this method to read and replace the CSS link. Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:56:28+00:00Added an answer on May 27, 2026 at 2:56 am

    Well, the short answer is that it works quite similar to shouldOverrideUrlLoading(WebView view, String url), as illustrated in the WebView tutorial.

    To get you started, see the code below. You simply override the shouldInterceptRequest(WebView view, String url) method of your WebViewClient. Obviously you don’t have to do that inline, but for the sake of compactness that’s what I did:

        WebView webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
                if (url.contains(".css")) {
                    return getCssWebResourceResponseFromAsset();
                } else {
                    return super.shouldInterceptRequest(view, url);
                }
            }
    
            /**
             * Return WebResourceResponse with CSS markup from a String. 
             */
            @SuppressWarnings("deprecation")
            private WebResourceResponse getCssWebResourceResponseFromString() {
                return getUtf8EncodedCssWebResourceResponse(new ByteArrayInputStream("body { background-color: #F781F3; }".getBytes()));
            }
    
            /**
             * Return WebResourceResponse with CSS markup from an asset (e.g. "assets/style.css"). 
             */
            private WebResourceResponse getCssWebResourceResponseFromAsset() {
                try {
                    return getUtf8EncodedCssWebResourceResponse(getAssets().open("style.css"));
                } catch (IOException e) {
                    return null;
                }
            }
    
            /**
             * Return WebResourceResponse with CSS markup from a raw resource (e.g. "raw/style.css"). 
             */
            private WebResourceResponse getCssWebResourceResponseFromRawResource() {
                return getUtf8EncodedCssWebResourceResponse(getResources().openRawResource(R.raw.style));
            }
    
            private WebResourceResponse getUtf8EncodedCssWebResourceResponse(InputStream data) {
                return new WebResourceResponse("text/css", "UTF-8", data);
            }
    
        });
    
        webview.loadUrl("http://stackoverflow.com");
    

    Catch the loading of the css file and return your own WebResourceResponse containing the data you want to load in stead.

    Do note that this method requires API level 11.

    If you want to do something similar for Android 2.x, you might want to try using the earlier mentioned shouldOverrideUrlLoading(WebView view, String url) to avoid loading the page, fetch it manually, replace the reference to the css file with your own, and finally call loadData(String data, String mimeType, String encoding) (or loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)) on the WebView, passing in the manipulated html content as a string.

    Before:

    Before

    After:

    After

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to know how does this thing work? By this i mean all
Hello I am new to PHP and I don't know exactaly what does this
I need to know which views does a user have which privileges on. I'm
Does anyone know what would be the minimum rights I would need to grant
Does anyone know the display formatter that I would need to add to the
Does anybody know of a Windows FTP client with SOCKS support? I need it
Does anyone know a good practice of securing media for asp.net? I need to
does anyone know of a good way of doing the following, I need to
Does anyone know why my site is all messed up on safari? I need
does anybody know how to call C++ functions or methods via JavaScript. Need scripting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.