From b16eea670ce995d9a31ff0095f17273a46c4f1e2 Mon Sep 17 00:00:00 2001 From: fabianterhorst Date: Sat, 21 May 2016 13:18:08 +0200 Subject: [PATCH] better style support --- app/src/main/res/layout/activity_main.xml | 1 + app/src/main/res/values/styles.xml | 6 +++++- .../fastlayout/converters/LayoutConverter.java | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8be59ba..cd1957e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -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" diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f3c931a..4c2eb46 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -7,9 +7,13 @@ @color/colorPrimaryDark @color/colorAccent - + + + diff --git a/fastlayout-converters/src/main/java/io/fabianterhorst/fastlayout/converters/LayoutConverter.java b/fastlayout-converters/src/main/java/io/fabianterhorst/fastlayout/converters/LayoutConverter.java index 2e0882b..f213af9 100644 --- a/fastlayout-converters/src/main/java/io/fabianterhorst/fastlayout/converters/LayoutConverter.java +++ b/fastlayout-converters/src/main/java/io/fabianterhorst/fastlayout/converters/LayoutConverter.java @@ -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")) {