Android Question set default font

Discussion in 'Android Questions' started by yaniv hanya, Jul 22, 2019.

  1. yaniv hanya

    yaniv hanya Member Licensed User

    Another beginner's question.
    I have a certain font that I need to use.
    Where do I put his files?
    And how do I set it to be the default font of the entire application?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can set the font with the designer. Add the font file to the designer files and then switch the Typeface.

    You can also do it programmatically:
    Code:
    Dim fnt As Typeface  = Typeface.CreateNew(...)
    For Each v As View In Activity.GetAllViewsRecursive
       
    If v Is Label Then
           
    Dim lbl As Label = v
           lbl.Typeface = fnt
       
    End If
    Next
    This exact code will work with EditText, Button, Label, CheckBox, RadioButton and ToggleButton as well as they are subtypes of label.
     
    MarkusR likes this.
  3. yaniv hanya

    yaniv hanya Member Licensed User

    Thanks. I'll try it.
    But is there a way to determine that this font will be the default?
    After all, the controls are created in the designer with the value at default
    and not with a reference to a particular font.
     
  4. Brandsum

    Brandsum Active Member Licensed User

  5. yaniv hanya

    yaniv hanya Member Licensed User

    Hi
    you siad in this post
    what should change it to
     
  6. Brandsum

    Brandsum Active Member Licensed User

    Replace that with the base theme you are using for your app. If you cant figure it out then post your manifest.
     
  7. yaniv hanya

    yaniv hanya Member Licensed User

    this is the msnifest
     
  8. Brandsum

    Brandsum Active Member Licensed User

    Code:
    CreateResource(values, theme.xml,
    <resources>
        <style name=
    "MyTheme" parent="android:Theme.Holo">
            <item name=
    "android:fontFamily">@font/CustomFontStyle</item>
            <item name=
    "fontFamily">@font/CustomFontStyle</item>
        </style>
    </resources>
    )
    SetApplicationAttribute(android:theme, 
    "@style/MyTheme")
     
    jimmyF likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice