Thursday 26 October 2017

How to change fontFamily of TextView in Android

itemprop="text">

So I'd like to change the
android:fontFamily in Android but I don't see any pre-defined
fonts in Android. How do I select one of the pre-defined ones? I don't really need to
define my own TypeFace but all I need is something different from what it shows right
now.




android:id="@+id/HeaderText"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"


android:layout_centerHorizontal="true"

android:layout_marginTop="52dp"
android:gravity="center"

android:text="CallerBlocker"
android:textSize="40dp"

android:fontFamily="Arial"

/>


It seems what I
did up there won't really work! BTW android:fontFamily="Arial"
was a stupid attempt!



class="post-text" itemprop="text">
class="normal">Answer



From
android 4.1 / 4.2 / 5.0, the following href="https://material.google.com/resources/roboto-noto-fonts.html"
rel="noreferrer">Roboto font families are
available:



android:fontFamily="sans-serif"
// roboto regular
android:fontFamily="sans-serif-light" // roboto
light
android:fontFamily="sans-serif-condensed" // roboto
condensed
android:fontFamily="sans-serif-black" // roboto
black
android:fontFamily="sans-serif-thin" // roboto thin (android
4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android
5.0)



href="https://i.stack.imgur.com/M2yxI.png" rel="noreferrer"> src="https://i.stack.imgur.com/M2yxI.png" alt="enter image description
here">



in combination
with



android:textStyle="normal|bold|italic"


this
16 variants are
possible:





  • Roboto
    regular

  • Roboto
    italic

  • Roboto bold

  • Roboto
    bold italic

  • Roboto-Light

  • Roboto-Light
    italic

  • Roboto-Thin

  • Roboto-Thin
    italic

  • Roboto-Condensed


  • Roboto-Condensed
    italic

  • Roboto-Condensed
    bold

  • Roboto-Condensed bold
    italic

  • Roboto-Black

  • Roboto-Black
    italic

  • Roboto-Medium

  • Roboto-Medium
    italic



fonts.xml




            version="1.0" encoding="utf-8"?>

name="font_family_light">sans-serif-light
name="font_family_medium">sans-serif-medium
name="font_family_regular">sans-serif
name="font_family_condensed">sans-serif-condensed

sans-serif-black

name="font_family_thin">sans-serif-thin




No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...