I like styling my android views from external styles.xml files. I was wondering what approach can I take to apply externalized styles to views that are created programatically and not in XML layout files, for example, views to be inserted on a ViewPager.
Another use case for this would be styling from XML files custom components that don’t have a corresponding XML layout.
Any help would be appreciated 🙂
Ideally you’d be able to use the View’s constructor that accepts the int defStyle attribute. While I haven’t used this constructor there may be an issue with styles not being applied. It sounds like standard views may not handle the style in an expected way. Unfortunately, it sounds like your best bet might be subclass the view and override the constructor to ensure that your style is correctly applied. I’d also take a look at the source code of view to see how styles are handled in View.java’s constructor. Hope this helps.