I am making custom buttons for my app and want to set the f开发者_运维问答ont they are using within the custom button class (extending Button). I can set the font from the main class with the following code:
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Korean_Calligraphy.ttf");
custom_button.setTypeface(font);
which works fine, but I have multiple buttons to apply this too and for the sake of tidy and succinct code, would rather everything was handled inside the button class itself. So two questions:
- How do I access the TextView of the Button from within my custom button class?
- How do I reference the font file as it seems to not let me use getAssets() within the button class?
Many thanks.
How do I access the TextView of the Button from within my custom button class
Button
IS A TextView
so you don't need to do anything special here. Just work with a button like with a regular text view.
How do I reference the font file as it seems to not let me use getAssets() within the button class?
Obtain a Context
instance and use its getAssets()
:
Context context = getContext();
context.getAssets()... //do anything you need
精彩评论