1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Changing font dynamically

Discussion in 'Android Questions' started by MitchBu, May 9, 2019.

  1. MitchBu

    MitchBu Active Member Licensed User

    I would like to enable the user to change font in y app.

    I searched the forum to find a way to change font dynamically in an EditText, as opposed to within the Designer, but all I found was an old post of mine dating from 2016, which never receive any reply:
    https://www.b4x.com/android/forum/t...yles-for-the-standard-font.72699/#post-462415

    The best I could find is below, but it is valid only for a string. And it is not quite clear about Bold and Italic. Although there is an example for Underline, so I will try to experiment.

    https://www.b4x.com/android/forum/threads/charsequence-csbuilder-tutorial.76226/#content

    But what I would really like to do is to change the typeface for anything that will be typed, just like I would do in the Designer.

    Any help will be greatly appreciated :)
     
  2. mangojack

    mangojack Well-Known Member Licensed User

    Slightly confused .. looking at your question here that went unreplied, it would appear you wish to use Roboto-Thin ttf.
    https://www.b4x.com/android/forum/t...yles-for-the-standard-font.72699/#post-462415

    Yet in another thread you received an answer how to achieve this (albeit a Label) ..
    https://www.b4x.com/android/forum/threads/custom-fonts-issues.72610/#post-461725

    So above you ask .. "a way to change font dynamically in an EditText"

    Code:
    Dim roboto As Typeface
        roboto = 
    Typeface.LoadFromAssets("Roboto-Thin.ttf")
    'OR roboto = Typeface.CreateNew(Typeface.LoadFromAssets("Roboto-Thin.ttf"), Typeface.STYLE_ITALIC)
        EditText1.Typeface = roboto

    But you also ask ..
    Unsure if there is a Font chooser / dialogue.
    You could use this lib https://www.b4x.com/android/forum/threads/customfonts.85264/#content
    Then possibly set up some font example labels contained in a panel, to be presented to the user.. unless there is something available.
     
    MitchBu and José J. Aguilar like this.
  3. MitchBu

    MitchBu Active Member Licensed User

    Mangojack, I see you have gathered all I need to do what I want to do.

    Since 2016, I had even forgotten about that answer.

    Thank you so much.
     
    Last edited: May 13, 2019
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