I want to embed a custom font into my android app. I don't use TextView so such tutorials as this one (How to use custom font with TextView) do not help.
In my case, the content is taken from the SQLite database and shown on the screen using WebView. I don't either use bundled HTML files so this tutorial (How to use custom font with WebView) does not solve my problem, either.
FIY, here is my code:
public void initWebview()
{
WebSettings settings = wvContent.getSettings();
settings.setDefaultTextEncodingName("utf-8");
setContentView(R.layout.content);
wvContent = (WebView) findViewById(R.id.wvContent);
wvContent.setBackgroundColor(Color.argb(250, 250, 250, 250));
wvContent.getSettings().setSupportZoom(true);
wvContent.getSettings().setBuiltInZoomControls(true);
wvContent.setInitialScale(100);
wvContent.setWebViewClient(new WebViewClient()
{
public void onPageFinished(WebView view, String url)
{
if (pd != null)
{
pd.dismiss();
pd = null;
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.i(CONTENT_TAG,"WebView link clicked; url = " + url);
try
{
String arrUrlPart[] = url.split("://");
if (arrUrlPart[0].equals("entry"))
{
String content = getContentByWord(arrUrlPart[1]);
showContent(content);
}
else if (arrUrlPart[0].equals("http"))
{
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} catch (Exception ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
return true;
}
});
}
The font stored in assets/fonts seems to be embedded into the app, and my questions are:
- How can I programmatically do to "force" my app to use this font?
- Are there any solutions to my problem?
Thank you very much.