Ask Your Question
3

How to reuse a style in NativeWind?

asked 2022-10-25 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-02-05 10:00:00 +0000

devzero gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-25 11:00:00 +0000

Seen: 11 times

Last updated: Feb 05 '22