Rajubhai Rathod
Rajubhai Rathod

Reputation: 113

Custom Font in Android WebView issue

I am facing issue in see Gujarati Language in WebView of my one android news application. I have got success in see gujarati language in TextView....I have tried many tutorial for find solution of webView custom font. My code is like below for webView. Please check and help me for get solved it !

String mimeType = "text/html; charset=UTF-8";
        String encoding = "UTF-8";
        String htmlText = allArrayNewsDes[position];

        String text = "<html><head>"
                + "<style type=\"text/css\">body{color: #525252;}"
                + "</style></head>"
                + "<body>"                          
                +  htmlText
                + "</body></html>";

        webnewsdes.loadData(text, mimeType, encoding);

        container.addView(imageLayout, 0);
        return imageLayout;

    }

Upvotes: 1

Views: 79

Answers (1)

Hardik Hirpara
Hardik Hirpara

Reputation: 3016

     String str1 = "<html><head><style type=\"text/css\">@font-face {font-family: 
     MyFont;src: url(\"file:///android_asset/fonts/FontName.otf\")}body {font- 
     family: MyFont;}</style></head><body>";

     String str2 = "</body></html>";
     String myHtmlString = str1 + your content + str2;
     webView.loadDataWithBaseURL(null,myHtmlString, "text/html", "UTF-8", null);

Upvotes: 1

Related Questions