android - How to change the font of the Switch in xml? - android

I can change the textview's fonts with using android:fontFamily="#font/test2"
but this is not working on switches, so i created a custom style includes font but still no action. Also I tried with android:textAppearance="#font/test2"
still no action. I can change the font just programmatically. How can I change with using xml attributes?

android:fontFamily atribute in xml is not available for API levels below 16.
For API below 16 use app namespace.

Related

How to set color of a TextView's Drawable in XML - for Android API 15?

My app is using minSdkVersion 15 and I would like to set the color of a TextView's drawable using XML.
There is a solution to a similar question, but it requires API 23.
I'm currently changing the drawable color programmatically, but I would rather do it in XML - if it's possible to do what with API 15?

setting font for a project

currently practicing making an application using android studio.
I have this customized font and saved into res/font directory for the later use.
Inside the activity, i am trying to call getfont(R.font.my_customized_font) with the typeface object. ex) Typeface font = getResources().getfont(R.font.mycustomizedfont)
However, when i try to run the project with the actual device which has the API level 24, it won't activate since the getfont() method requires the min sdk level with 26.
I know that you can set the font of text view in the xml file by doing android:fontfamily but i am using the textswitcher instead of textview.
Emulator works fine by setting up min sdk with 26 but I would like to figure this out by using the actual device.
I found the solution by reading through the developer's website
I just added Typeface font = ResourcesCompat.getfont(context, R.font.mycustomizedfont)
I use a Min API of 21 and this works for me:
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/mycustomizedfont");
Then, to set the font to a the child TextViews:
text_view.setTypeface(type);
Hope this helps!
You can use via xml layout simple is that just use like this:-
android:fontFamily="#fonts/avenir"
Instead of avenir use your font name under res/font folder.
Hope it will help you.
I found the solution by reading through the developer's website I just added Typeface font = ResourcesCompat.getfont(context, R.font.mycustomizedfont)
to apply the font programmatically

Setting font in Android

In android Using setTypeface method we can set the font to the control of our wish programmatically, but i want to know is there a way we can avoid this and set the font in layout XML file itself?
I Just want to specify the path of the file & font should get updated automatically.
You can use Calligraphy library where you can specify font in XML itself.
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fontPath="fonts/Roboto-Bold.ttf"/>
Yes. You need to extend the view you want to set its font in xml and then make an custom attribute (as enum) to be accessed from xml and call it for example "customFont".
Then in the extended view java code get the "customFont" value and change the font programaticaly.
Then you can use this custom view and set its font through xml ;)
Its possible for some limited font becuase you must define an enum for xml and see in java code wich font was selected and then set it in java code set the selected font.
Though you can set system font in xml without all these. And my explanation was for your custom fonts ;)

Appcelerator , can not change tabsBackgroundColor in android

The attribute tabsBackgroundColor in tagGroup tag not working on android
<TabGroup tabsBackgroundColor="#a466a3">
and backgroundColor not working too , although it is written in the documentation
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TabGroup
You'll need to modify your theme file / create a custom android theme to set the appearance of of your tabs.
http://docs.appcelerator.com/platform/latest/#!/guide/Android_Themes
If you read that you'll see how to add and setup a custom theme to override the base theme that Titanium gives you.
The XML property you'll want to modify for the background colour is actionBarTabStyle
A helpful but old tool that you can use to auto generate this is https://jgilfelt.github.io/android-actionbarstylegenerator/

Android fontFamily sans-serif-light

I need some clarification regarding sans-serif-light font for android. The following line of code
<item name="android:fontFamily">sans-serif-light</item>
in custom style say <style name="custom_style"/> gives an error if minSdkVersion is less than 16.
but the same property directly on a textview
android:fontFamily="sans-serif-light"
gives a warning if the minSdkVersion is less than 16.
Q1 What is the difference between the 2 approaches?
Q2 If i set the property directly in textview (2nd way) will the application be compatible with sdk version below 16 with the default font?
(I have only one device with android 4.4.4 and it works great on it with both ways)
If i set the property directly in textview (2nd way) will the
application be compatible with sdk version below 16 with the default
font?
The behaviour should not change even if you set the font family in the styles. The difference is probably due to your Lint's settings.
As blackbelt said, it must be due to difference in lint settings.
San-serif light font will NOT work in devices below API 16. To fix this, you need to upload a custom font (.ttf file) file in asset.
Here is how to do it -
First copy the san-serif light font .ttf file to your asset folder which you can download from here. The file will contain many fonts but you just need san-serif light file.
Then in your code, do this -
Typeface light = Typeface.createFromAsset(getContext().getAssets(), "san-serif-light.ttf");
//Make sure that the font file's name is actually san-serif-light
Then you can set this to a textview this way -
textview.setTypeface(light);

Categories

Resources