2016-11-13 7 views
3

Android 앱에서 맞춤 글꼴을 사용하고 싶습니다. TextView의 사용자 정의 글꼴이 제대로 작동하지만 WebView에 맞춤 (유니 코드) 글꼴을 추가하는 방법을 찾지 못했습니다. 가능한 모든 방법을 시도했지만 실패했는지, 내가 놓친 코드인지 살펴 보았습니다. 고맙습니다.!Android 앱에 WebView에서 사용자 정의 (유니 코드) 글꼴 사용

애셋 폴더에 맞춤 글꼴 모음이있는 CSS 파일을 만들고 LoadDataWithBaseURL이라고했지만 작동하지 않습니다.

 htmlTextView = (WebView) findViewById(R.id.htmlTextView); 

     String text = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />"; 
     htmlTextView.loadDataWithBaseURL("file:///android_asset/", text, "text/html", "UTF-8", null); 

     htmlTextView.getSettings().setJavaScriptEnabled(true); 
     htmlTextView.setBackgroundColor(Color.TRANSPARENT); 
     htmlTextView.getSettings().setDefaultFontSize(
       WebHelper.getWebViewFontSize(this)); 

CSS 파일 :

@font-face { 
    font-family: 'iskoola pota'; 
    src: url('fonts/iskpota.ttf') format('truetype'); 
} 

답변

0

있는 방법

webView.loadUrl("file:///android_asset/html/index.html"); 

HTML은 다음과 같이 index.html을 파일에 HTML 코드를 넣고있다. 대한 ..

@font-face { 
    font-family: trado; 
    src: url('file:///android_asset/fonts/trado.ttf'); 
} 

가 작동 희망 ..., 당신은 자산 폴더에 글꼴 파일을 둘 필요가

<html> 
<head><LINK href="file:///android_asset/css/myStyle.css" type="text/css" rel="stylesheet"/></head> 
<body> 
    <img class="img" src="file:///android_asset/img/ok.png"> 
    <p > This above image is shown from assets folder... </p> 
    <p>Custom font <span style="color:red">'trado'</span> from asset folder has been applied on this text</p> 
</body> 

와 CSS는 다음과 같이됩니다 자산 폴더에서 CSS 파일을 호출 github에 대한 완벽한 예 click

+0

나는 html 파일을 사용하고 싶지 않다. 내 워드 프레스 기반 안드로이드 앱의 게시물에 맞춤 (유니 코드) 글꼴을 사용하고 싶다. – SNoV