简体   繁体   中英

Changing Font-Family Property of a Label via Nativescript on Android

I have the following code with js to change the Font-Family of a Label. The idea is to access the native API of android to change the Font-Family, but it seems not to work. Any ideas what the problem is ?

foo.xml:

<Label text="foo" id="blogHead" textWrap="true"
            cssClass="margin-20 verticalCenter" fontSize="24" />

foo.js:

var heading = view.getViewById(page, "blogHead");
heading.android.setTypeface(android.graphics.Typeface.create("Courier New", android.graphics.Typeface.NORMAL));

Courier New is remapped to another font.

See here for a list of fonts and their aliases that are built-in. To understand the difference you might try something like the following code (any valid font can be used in place of sans-serif-light here):

var heading = view.getViewById(page, "blogHead");
heading.android.setTypeface(android.graphics.Typeface.create("sans-serif-light", android.graphics.Typeface.NORMAL));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM