This message was deleted.
# android-architecture
s
This message was deleted.
a
You can define a font family and set a font weight for specific font and ally the style to the TextView with specific font family type. Check this article https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml
u
Not really. How can you apply weight=200 (thin) at callsite?
afaik you can only choose textStyle=regular/bold
a
One way is to apply style, there you have weight parameter defined or you can define font weight from compat library... It was
app:fontWeight
or something like this.
if so, that only works for me api 28+, app:textFontWeight on android 6 does nothing
a
ok, you right. I did accomplished it differently using styles.
Copy code
<style name="MyFontLight">
        <item name="fontFamily">@font/arima_madurai_light</item>
    </style>
    <style name="MyFontLightItalic">
        <item name="fontFamily">@font/arima_madurai_light</item>
        <item name="android:textStyle">italic</item>
    </style>
    <style name="MyFontMedium">
        <item name="fontFamily">@font/arima_madurai_medium</item>
    </style>
    <style name="MyFontMediumItalic">
        <item name="fontFamily">@font/arima_madurai_medium</item>
        <item name="android:textStyle">italic</item>
    </style>
    <style name="MyFontBold">
        <item name="fontFamily">@font/arima_madurai_bold</item>
    </style>
    <style name="MyFontBoldItalic">
        <item name="fontFamily">@font/arima_madurai_bold</item>
        <item name="android:textStyle">italic</item>
    </style>
    <style name="MyFontExtraBold">
        <item name="fontFamily">@font/arima_madurai_extrabold</item>
    </style>
    <style name="MyFontExtraBoldItalic">
        <item name="fontFamily">@font/arima_madurai_extrabold</item>
        <item name="android:textStyle">italic</item>
    </style>
and usage is something following
Copy code
<TextView
            style="@style/MyFontLight"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/custom_font" />

    <TextView
            style="@style/MyFontLightItalic"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/custom_font" />

    <TextView
            style="@style/MyFontMedium"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/custom_font" />

    <TextView
            style="@style/MyFontMediumItalic"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/custom_font" />

    <TextView
            style="@style/MyFontBold"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/custom_font" />

    <TextView
            style="@style/MyFontExtraBold"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/custom_font" />
result is like expected
It would be great if the compat attribute would work similar in compat library (even though I was sure I saw it working).
u
yea, I also wanted styles, but my issue was that it needs to a attr, and you cannot inteherit thos if you need a style which inherits from your MyFontBold for example
youd just easily FooStyle parent=MyFontBold", but you cannot have parent="?attr/fontBoldStyle"
a
I'm not sure about your exact need, but if you just need to override some fonts you can use
ThemeOverlay
theme for this and define fonts via it. In this case you will be able to use regular
style="@style/***"
for any other adjustments you need.