s

    Slackbot

    2 years ago
    This message was deleted.
    aipok

    aipok

    2 years ago
    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

    ursus

    2 years ago
    Not really. How can you apply weight=200 (thin) at callsite?
    afaik you can only choose textStyle=regular/bold
    aipok

    aipok

    2 years ago
    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
    aipok

    aipok

    2 years ago
    ok, you right. I did accomplished it differently using styles.
    <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
    <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

    ursus

    2 years ago
    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"
    aipok

    aipok

    2 years ago
    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.