Open AbimbolaE opened 8 years ago
The style can be passed to a view's constructor. There are no other options to use styles programmatically.
The best approach is to re-write your style as Tweak
s,
thus:
val login_style = Tweak[EditText] { e: EditText =>
e.setXXX(...)
e.setYYY(...)
e.setZZZ(...)
}
w[EditText] <~ login_style
if on v21+, you can do:
new EditText(context, null, 0, R.style.login_field)
if before v21, you must do:
styles.xml:
<attr name="myEditStyle" format="reference"/>
<style name="MyAppTheme" parent=...> <!-- or use your existing AppTheme if set -->
<item name="myEditStyle">@style/login_field</item>
</style>
in code:
new EditText(context, null, R.attr.myEditStyle)
However!!!
You are attempting to change theme attributes, which is not handled by any of the above (colorControlXXX are theme attributes, you wouldn't be able to apply this in xml via style=
either, additionally, since you are attempting to override theme attributes, you should remove the parent from login_field
as well), what you need to do is:
new EditText(new ContextThemeWrapper(context, R.style.login_field)), null, 0)
So assuming I wanted to do the following:
new EditText(context, null, R.attr.myEditStyle)
Is there any clean way of achieving this using Macroid? Or do I have to manage the EditText using the Android API like in regular Java?
Ui(new EditText(context, null, R.attr.myEditStyle) <~ tweak
On Wed, Feb 3, 2016 at 8:43 PM Abimbola Esuruoso notifications@github.com wrote:
So assuming I wanted to do the following:
new EditText(context, null, R.attr.myEditStyle)
Is there any clean way of achieving this using Macroid? Or do I have to manage the EditText using the Android API like in regular Java?
— Reply to this email directly or view it on GitHub https://github.com/47deg/macroid/issues/73#issuecomment-179635095.
That was bloody fast mate.... Thanks, I'll try it!
Ui(new EditText(context, null, R.attr.myEditStyle) <~ tweak
IIRC widget[EditText](null, R.attr.myEditStyle)
should be the same.
I have an EditTextView and I would like to change the style to match the following xml:
However according to this post on StackOverflow setting a style isn't possible programmatically. How can I achieve this in Macroid??