android-fonts

Unable to add custom font in RecyclerView.ViewHolder

浪尽此生 提交于 2019-12-06 09:27:38
问题 I am working on an android project and I added custom fonts on few layouts successfully. But when I tried adding them in a class which is not an activity which extends RecyclerView.ViewHolder, it creates a null pointer exception. I tried looking for but no luck. Initially I did not use context.getAssets(), I only used getAssets(). But then I was getting "cannot resolve method" on getAssets(). Since getAssets() is a part of Context, I included context and then all the errors went away. But

Custom fonts for TextView based on languages inside String

人盡茶涼 提交于 2019-12-06 05:44:21
问题 I have two font ttf files that must be applied on a TextView based on languages inside String . So e.g. consider this sample text: hey what's up ضعيف I can just apply a typeface span based on language but it requires custom markup in every string that is fetched from our server e.g. <ttf1>hey what's up <ttf1><ttf2>ضعيف</ttf2> And parsing every String at run time will give a performance hit. Is there any other approach to achieve this? For start lets say I need to do this just for direction of

How to add locale(with country) to font resources (Support Library v26)?

蓝咒 提交于 2019-12-05 03:13:09
Google published the official font resources handling since support library v26 released: https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html However, looks like I cannot add country qualifier for the font resources folder. I have an app which has 3 languages: English, Traditional Chinese and Simplified Chinese. And I tried to name my font folder under res this way: font font-zh font-zh_CN (I have also tried font-zh-CN ) (Note that zh is the language, while CN is the country. With some more context for your information - In China we all use "Chinese", but there are

Setting Button text font in android

无人久伴 提交于 2019-12-04 23:37:56
I have a button created using android widgets. I want to set the font of the button text to Helv Neue 67 Med Cond . How to get this font and set it to the button text in android layout file? First you have to put the ttf file in assets folder and then You can use the below code to set Custom font in TextView, same way you can do for Button: TextView txt = (TextView) findViewById(R.id.custom_font); Typeface font = Typeface.createFromAsset(getAssets(), "Helv Neue 67 Med Cond.ttf"); txt.setTypeface(font); Ann I guess you may have already found the answer, but if not (and for other developers),

I don't use unicode characters in my android-textview.How can I do this?

烂漫一生 提交于 2019-12-04 21:13:30
I don't use unicode characters in my android-textview.How can I do this? my xml : <?xml version="1.0" encoding="utf-8"?> and I don't use unicode characters in android textview,edittext,.... Summary of comment thread: Save .txt file containing şile as UTF-8. (For Notepad, best: UTF-8 without BOM.) Load from code using a new InputStreamReader(inputStream, "utf-8") . 来源: https://stackoverflow.com/questions/9108876/i-dont-use-unicode-characters-in-my-android-textview-how-can-i-do-this

Unable to add custom font in RecyclerView.ViewHolder

人走茶凉 提交于 2019-12-04 17:14:19
I am working on an android project and I added custom fonts on few layouts successfully. But when I tried adding them in a class which is not an activity which extends RecyclerView.ViewHolder, it creates a null pointer exception. I tried looking for but no luck. Initially I did not use context.getAssets(), I only used getAssets(). But then I was getting "cannot resolve method" on getAssets(). Since getAssets() is a part of Context, I included context and then all the errors went away. But when I run the app I get the runtime exception. I thinking it should something simple but I am sure I am

How to change ActionBar title font when using AppCompat

百般思念 提交于 2019-12-03 05:59:09
问题 I would like to apply custom font to the title of my app which is displayed on the ActionBar. Previously I didn't use any support library and this solution: int titleId = getResources().getIdentifier("action_bar_title", "id", "android"); TextView yourTextView = (TextView) findViewById(titleId); yourTextView.setTypeface(face); worked fine for me. But now I am using material design SupportActionBar and this throws NullPointerException. So how to change the ActionBar font when using AppCompat?

How do I specify eg. Roboto-Medium or Roboto-Black in styles.xml

蓝咒 提交于 2019-12-03 01:00:17
问题 Posts like this How to change fontFamily of TextView in Android suggests, that the variants of Roboto fonts you can specify in styles.xml in Android 4.2 boils down to the following: Regular Italic Bold Bold-italic Light Light-italic Thin Thin-italic Condensed regular Condensed italic Condensed bold Condensed bold-italic That leaves out the ability to style TextViews using eg. the Roboto-Medium or Roboto-Black fonts. But why would Google add system wide fonts that can not be used for styling

How do I specify eg. Roboto-Medium or Roboto-Black in styles.xml

我的梦境 提交于 2019-12-02 14:21:30
Posts like this How to change fontFamily of TextView in Android suggests, that the variants of Roboto fonts you can specify in styles.xml in Android 4.2 boils down to the following: Regular Italic Bold Bold-italic Light Light-italic Thin Thin-italic Condensed regular Condensed italic Condensed bold Condensed bold-italic That leaves out the ability to style TextViews using eg. the Roboto-Medium or Roboto-Black fonts. But why would Google add system wide fonts that can not be used for styling of your TextViews? Surely there must be some way of specifying all of the Roboto fonts from within

Set font size on phone and tablet

耗尽温柔 提交于 2019-12-02 08:20:31
How to set the font size for a textview in a phone and a tablet. The posts I've referred suggested to creating dimen.xml and placing them in different folders namely values-mdpi , values-hdpi , values-ldpi . The tablet (1024x600) resolution picks from the values-mdpi folder and so does the the phone (320x480) also picks from the values-mdpi folder, this makes the font look really big and distorted on the phone, whereas it looks fine on the tablet. Is there any way to specify a font size for the phone and tablet separately. For tablets I use: values-sw600dp for 7″ values-sw720dp for 10″ This