Issue
Here's my attr:
<attr name="taskTimePickerLayout" format="reference" />
And here's how it's set in themes.xml:
<item name="taskTimePickerLayout" type="reference">@layout/task_time_picker_holo</item>
I want to inflate a layout using the layout in the attr, how do I do that? I've tried using R.attr.taskTimePickerLayout
as the resource for the inflater, but that throws a ResourceNotFoundException.
Solution
Put this piece of code into your Activity (or Fragment):
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.taskTimePickerLayout, typedValue, true);
setContentView(typedValue.resourceId);
Make sure you apply the theme to the Activity before executing this code.
What this code basically does is resolving the reference R.attr.taskTimePickerLayout based on the theme applied to the current Context. typedValue.resourceId is the value of the resolved reference (the layout id of @layout/task_time_picker_holo in this case). This works also with all other references (drawables, colors etc.)
Answered By - Emanuel Moecklin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.