Reputation: 2948
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.
Upvotes: 3
Views: 681
Reputation: 13495
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"/>
Upvotes: 1