Search code examples
androidchronometer

Text style on chronometer on android


How do I change the font ans font size on chronometer. When I align the chronometer with a textview it shows different size and settings. I also tried assigning font settings from textview.

chronometer.setTypeface(txtView.getTypeface());
chronometer.setTextSize(TypedValue.COMPLEX_UNIT_SP,txtView.getTextSize());

Solution

  • You can change the font style and font size on chronometer using following

    XML

    android:typeface="serif"
    android:textSize="120dp"
    

    in xml you can set default fonts of android.

    JAVA

            Typeface font = Typeface.createFromAsset(getAssets(), "fonts/opensanslight.ttf");
    
            focus = (Chronometer) findViewById(R.id.chronometer1);
            focus.setTypeface(font, Typeface.NORMAL);
            focus.setTextSize(120);
    

    where focus is chronometer.

    for custom fonts

    put your .ttf files in assets folder.

    in android studio you have to create assets folder under src/main/assets/