question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom view inflated in code doesn't get custom font

See original GitHub issue

I have a custom view with TextViews. Those TextViews have a custom font. If I include an instance of my custom view in XML as part of an activity the custom font will render correctly.

However, if I dynamically create an instance of my custom view the custom font is not applied.

CustomView customView = new CustomView(context);
this.addView(customView);

Inside of my custom view I am inflating the XML:

LayoutInflater.from(context).inflate(R.layout.custom_view, this, true);

As I say, it works correctly unless I create the view dynamically at runtime. Is this a genuine issue or am I overlooking something?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisjenxcommented, Apr 1, 2016

Yeah, that would make perfect sense. There should be a lint check for that.

On Fri, 1 Apr 2016, 16:57 Tarekk Mohamed Abdalla, notifications@github.com wrote:

I had this issue if i set the Context to getApplicationContext() . But I fixed it with this as context

— You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/170#issuecomment-204448796

0reactions
TarekkMAcommented, Apr 1, 2016

I had this issue if i set the Context to getApplicationContext() . But I fixed it with this as context

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a custom View by inflating a layout? - Stack Overflow
What you want to do is create a Compound Control. You'll create a subclass of RelativeLayout, add all our your components in code...
Read more >
The beauty of Custom Views in Android and How to do it!
You will learn how to inflate a custom layout for your view and pass two different parameters. It's quick and easy! The code...
Read more >
Creating a Custom View in Android
What are Custom Views? ... A custom view is a view that you design in any way you want by extending another view...
Read more >
Dialogs - Android Developers
You can accomplish a wide variety of dialog designs—including custom layouts and those described in the Dialogs design guide—by extending ...
Read more >
Writing a Custom Android View - Conjure
This article will demonstrate the different ways you can create a custom Android View and provide guidance on when to use each approach....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found