Skip to content

Commit

Permalink
better style support
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianTerhorst committed May 21, 2016
1 parent b5da589 commit b16eea6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_margin="5dp"
style="@style/MyTextView.MyTextStyle2"
android:clickable="true"
android:weightSum="1"
android:orientation="horizontal"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="MyTextView">
<item name="android:textSize">10sp</item>
</style>

<style name="MyTextView.MyTextStyle2">
<item name="android:textColor">@color/colorAccent</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public LayoutAttribute onConvertLayoutAttributeValue(Object attributeValue, Stri
return onConvertLayoutAttribute(attribute, "getContext().getColor(" + attribute + ")", attributeName, false);
} else if (attribute.startsWith("R.drawable.") || attribute.startsWith("R.mipmap.") || attribute.startsWith("R.attr.")) {
return onConvertLayoutAttribute(attribute, "LayoutUtils.getAttrDrawable(getContext(), " + attribute + ")", attributeName, false);
} else if (attribute.startsWith("R.style.")) {
String attributeStyle = attribute.replace("R.style.", "");
String style = attributeStyle.replace(".", "_");
String styleAttribute = "R.style." + style;
return onConvertLayoutAttribute(attribute, styleAttribute, attributeName, false);
} else if (attribute.endsWith("dp") && isNumber(attribute.replace("dp", ""))) {
return onConvertLayoutAttribute(attribute, "(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, " + attribute.replace("dp", "") + ", getResources().getDisplayMetrics())", attributeName, false);
} else if (attribute.equals("false") || attribute.equals("true")) {
Expand Down

0 comments on commit b16eea6

Please sign in to comment.