Skip to content

Margins defined in style.xml get ignored when using ContextThemeWrapper #417

Open
@xoif

Description

@xoif

Issues and steps to reproduce

  1. define Style for your view element (e.g. TextView):
<style name="style_text_black">
        <item name="android:textSize">12</item>
        <item name="android:textColor">@android:color/black</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginBottom">8dp</item>
        <item name="android:padding">8dp</item>
    </style>
  1. initialize ContextThemeWrapper to load the style
    ContextThemeWrapper themeWrapper = new ContextThemeWrapper(flexbox.getContext(),R.style.style_text_black);

  2. Create multiple new Textview instances and add them to FlexboxLayout

for (...) {
  TextView text = new TextView(themeWrapper);
                            text.setText("test");
  flexbox.addView(text);
}

Expected behavior

TextView elements appear in the flexbox layout while considering the margins from the applied style.

Observed behavior

Margins applied by a style using ContextThemeWrapper are ignored

I agree that this might be kind of an edge case, but it took me a few minutes of trying and browsing. Finally I ended up adding separate MarginLayoutParams to my Textviews.

Version of the flexbox library

flexbox:0.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions