Can I define attributes in a theme that will apply only on specific components, such as an EditText, like what can be done in CSS with, e.g, .table? I know I can define a style and set it on all the components, but I'm looking for a more efficient way.
In your theme, add <item name="android:editTextStyle">@style/<your substyle name>:
<style name="My.Mega.Theme" >
<item name="android:editTextStyle">@style/My.Mega.Theme.EditText</item>
</style>
<style name="My.Mega.Theme.EditText" parent="My.Mega.Theme">
<item name="android:textSize">14sp</item>
</style>
Replace editTextStyle with buttonStyle for buttons, and so on.
You can even have analogs of css classes for controls of the same class, like:
(styles file):
<attr name="note" format="reference" />
<style name="My.Mega.Theme" >
<item name="note">@style/My.Mega.Theme.SmallText</item>
</style>
(layout file):
<TextView style="?note"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With