مدیریت کاربران مشترک
بروز خطا
امتیازات دریافتی
حساب
آموزش هوش مصنوعی برای برنامه نویسان
وبینار ها
با این قطعه کد میتوانید فونت محتوای WebView را تغییر دهید
فونت شما باید در پوشه assets باشد، در اینجا فونت ما yourFont.ttf است.
در خط 7 نیز میتوانید اندازه فونت را تغییر دهید ( font-size ).
public static String htmlTemplate(Context mContext, String content, int bgColor, int textColor) {
String backgroundColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(mContext, bgColor)));
String contentColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(mContext, textColor)));
return "<html><head><style type=\"text/css\">@font-face {font-family: MyFont;"
+ " src: url(\"file:///android_asset/yourFont.ttf\")\n" + "}"
+ " body {color:" + contentColor + ";direction:rtl;background:" + backgroundColor
+ ";font-family: MyFont;font-size: 10pt;text-align: justify;}</style></head><body>\n"
+ content
+ "</body>\n" + "</html>";
}String temporaryData = "<p>Hello World!</p>";
String htmlContent = htmlTemplate(getApplicationContext(),temporaryData, R.color.colorPrimary, R.color.colorAccent);
final String mimeType = "text/html";
final String encoding = "UTF-8";
webView.loadDataWithBaseURL("file:///android_asset/",htmlContent, mimeType, encoding, "");