Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Add support for context.getTheme().resolveAttribute(...) #15

Open
ZacSweers opened this issue Apr 12, 2015 · 0 comments
Open

Add support for context.getTheme().resolveAttribute(...) #15

ZacSweers opened this issue Apr 12, 2015 · 0 comments
Labels

Comments

@ZacSweers
Copy link
Owner

Not high on my priority list right now, but will consider adding if people express an interest.


TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, outValue, true);
int primaryTextColor = outValue.data;

Have access to TypedValue means this could support a full range of checks to figure out its type. Doing so automatically might come at the expense of flexibility (e.g. user might want to force a particular type).

@ResolvedAttr(android.R.attr.textColorPrimary)
int primaryTextColor;

The default could be to resolve the attribute based on TypedValue's type, with an optional specifier.

Alternative approach.

Simpler for code generation, but more work for the user as they would have to figure out how to mix their desired attrs with these. Would need another overload for Style, and remove the hard requirement for attributeset not to be null in the generated Barbershop#style(...) method.

private static final int[] ATTRS = new int[]{
        android.R.attr.listDivider
};

// Want to do this boilerplate
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();

// Probable method signature
style(Object target, int[] attrs);
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant