From 8657baa06d2efe845cafef571bd9dce627cf5045 Mon Sep 17 00:00:00 2001 From: Deepanshu Gupta Date: Mon, 10 Nov 2014 20:10:55 +0000 Subject: [PATCH] Fix setting styles in custom views. Bug: http://b.android.com/78842 Change-Id: I5d4571d94d96b00419acc258c9e2b519367b689d --- .../layoutlib/bridge/android/BridgeContext.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java index 3d3afa4d8fe4b..aeb70e9e2f76d 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java @@ -478,6 +478,23 @@ public final class BridgeContext extends Context { // get the StyleResourceValue based on the resId; StyleResourceValue style = getStyleByDynamicId(resid); + if (style == null) { + // In some cases, style may not be a dynamic id, so we do a full search. + ResourceReference ref = resolveId(resid); + if (ref != null) { + if (ref.isFramework()) { + ref = + getRenderResources().getFrameworkResource(ResourceType.STYLE, ref.getName()); + } else { + ref = + getRenderResources().getProjectResource(ResourceType.STYLE, ref.getName()); + } + if (ref instanceof StyleResourceValue) { + style = ((StyleResourceValue) ref); + } + } + } + if (style == null) { throw new Resources.NotFoundException(); }