airbnb / paris

Define and apply styles to Android views programmatically

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting style overrides attributes in XML layout

UkiUros opened this issue · comments

If using my custom view, with some attributes (like gravity, maxLines, etc.) in the XML layout file and set some style for it using Paris lib, all these attributes are getting reset even when they are not in the new style.

Example:

<com.example.views.CustomTextView
    android:id="@+id/textViewFeedback"
    style="@style/Headline2"
    android:layout_width="@dimen/custom_diameter"
    android:layout_height="@dimen/custom_diameter"
    android:gravity="center"
    android:maxLines="3"
    android:paddingLeft="30dp"
    android:paddingRight="30dp"/>

If I set a new style using this line of code textViewFeedback.style(R.style.Headline1), attributes like gravity are getting overriden even if I do not have that field in my new style Headline1.

Is there a way to preserve these values?

P.S. I actually have more complex logic within the custom view, where I set the styles in the init block, for some cases, but I do not use any custom attributes.