use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ThemeTest method shouldApplyParentStylesFromAttrs.
@Test
@Ignore("todo: incorrect behavior on robolectric vs framework?")
public void shouldApplyParentStylesFromAttrs() throws Exception {
Resources.Theme theme = resources.newTheme();
theme.applyStyle(R.style.Theme_AnotherTheme, true);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from Theme.AnotherTheme");
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string3 }).getString(0)).isEqualTo("string 3 from Theme.Robolectric");
}
use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ThemeTest method applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues.
@Test
@Ignore("todo: incorrect behavior on robolectric vs framework?")
public void applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues() throws Exception {
Resources.Theme theme = resources.newTheme();
theme.applyStyle(R.style.Theme_Robolectric, false);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from Theme.Robolectric");
theme.applyStyle(R.style.Theme_AnotherTheme, false);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from Theme.Robolectric");
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string2 }).getString(0)).isEqualTo("string 2 from Theme.AnotherTheme");
}
use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ShadowThemeTest method applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues.
@Test
public void applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues() {
Resources.Theme theme = resources.newTheme();
theme.applyStyle(R.style.StyleA, false);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from style A");
theme.applyStyle(R.style.StyleB, false);
assertThat(theme.obtainStyledAttributes(new int[] { R.attr.string1 }).getString(0)).isEqualTo("string 1 from style A");
}
use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ShadowThemeTest method whenStyleSpecifiesAttr_obtainStyledAttribute_findsCorrectValue.
@Test
public void whenStyleSpecifiesAttr_obtainStyledAttribute_findsCorrectValue() {
Resources.Theme theme = resources.newTheme();
theme.applyStyle(R.style.Theme_Robolectric, false);
theme.applyStyle(R.style.Theme_ThemeContainingStyleReferences, true);
assertThat(theme.obtainStyledAttributes(Robolectric.buildAttributeSet().setStyleAttribute("?attr/styleReference").build(), new int[] { R.attr.string2 }, 0, 0).getString(0)).isEqualTo("string 2 from YetAnotherStyle");
assertThat(theme.obtainStyledAttributes(Robolectric.buildAttributeSet().setStyleAttribute("?styleReference").build(), new int[] { R.attr.string2 }, 0, 0).getString(0)).isEqualTo("string 2 from YetAnotherStyle");
}
use of android.content.res.Resources.Theme in project robolectric by robolectric.
the class ShadowThemeTest method obtainStyledAttributes_shouldFindAttributeInDefaultStyle.
@Test
public void obtainStyledAttributes_shouldFindAttributeInDefaultStyle() {
Theme theme = resources.newTheme();
TypedArray typedArray = theme.obtainStyledAttributes(R.style.StyleA, new int[] { R.attr.string1 });
assertThat(typedArray.getString(0)).isEqualTo("string 1 from style A");
}
Aggregations