Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To reuse a style in NativeWind, you can define the style in the styles.xml file and then reference it in other XML files where needed.

Here's an example:

  1. Define the style in the styles.xml file:
<style name="MyButtonStyle">
    <item name="nw_backgroundColor">@color/blue</item>
    <item name="nw_textColor">@color/white</item>
    <item name="nw_cornerRadius">8dp</item>
    <item name="nw_paddingHorizontal">16dp</item>
    <item name="nw_paddingVertical">8dp</item>
</style>
  1. Reference the style in an XML file where needed:
<Button
    android:id="@+id/my_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/MyButtonStyle"
    android:text="Click me" />

This will apply the "MyButtonStyle" to the Button, reusing the style definition from the styles.xml file. You can reference the same style in other XML files where you need to apply the same set of attributes.