Bug 10606 - drawable backgrounds are not applied in the design window
Summary: drawable backgrounds are not applied in the design window
Status: RESOLVED FEATURE
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Android Designer ()
Version: 5.7
Hardware: PC All
: Normal minor
Target Milestone: ---
Assignee: Jérémie Laval
URL:
: 16533 18426 ()
Depends on:
Blocks:
 
Reported: 2013-02-23 13:01 UTC by softlion
Modified: 2017-09-01 06:54 UTC (History)
10 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test case (11.69 KB, application/zip)
2015-01-05 15:00 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
IDE log files (3.47 KB, application/zip)
2015-01-05 15:02 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description softlion 2013-02-23 13:01:20 UTC
With the following code which sets the background of an ImageButton view to a drawable, the designer never display the correct UI. It completely ignores the background. It works perfectly in the simulator and on the device though.

            <ImageButton
                android:id="@+id/btn5"
                android:layout_width="90dp"
                android:layout_height="50dp"
                android:src="@drawable/Icon"
                android:background="@drawable/bottomTab_inactiveBtn"
                android:scaleType="fitCenter"
                android:layout_marginLeft="-35dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true" />

with a drawable shape in bottomTab_inactiveBtn.xml in the Drawable resource folder:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
      <shape>
        <solid android:color="#CCCCCC" />
        <corners android:radius="1dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"  />
        <padding android:left="6dp" android:top="6dp" android:right="6dp" android:bottom="6dp" />
      </shape>
    </item>

</layer-list>
Comment 1 Ross 2014-04-09 07:11:03 UTC
Had same issue with an ImageView widgets. It doesn't display pictures in the designer window, but it works ok on the emulator and the real device.
Comment 2 Lluis Sanchez 2014-05-08 13:04:50 UTC
*** Bug 18426 has been marked as a duplicate of this bug. ***
Comment 3 Lluis Sanchez 2014-05-08 13:05:50 UTC
The problem seems to be caused by the "<?xml version="1.0" encoding="utf-8"?>" directive. If you remove that line, the background is properly renderer. This is a problem in the Android SDK. We'll try to find a workaround.
Comment 4 Lluis Sanchez 2014-05-08 13:08:16 UTC
*** Bug 16533 has been marked as a duplicate of this bug. ***
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-05 15:00:44 UTC
Created attachment 9243 [details]
Test case

Updating with a zipped-up test case and some more verbose details since I wrote them up before I found this report.


## Steps to reproduce

1. Open the attached test case in Xamarin Studio.

2. Double-click "Resources/layout/Main.axml" in the solution pad to open the layout in the Android designer.


`Main.axml` includes an attribute `android:background="@drawable/shape_one"` to set the background to the `shape_one.xml` drawable resource.


## Results

The designer renders the Main layout with a black background rather than the cyan background from the "shape_one" resource.


### Error from `Ide.log` file

I think the corresponding error in `~/Library/Logs/XamarinStudio-5.0/Ide.log` is this:

> ERROR: org.xmlpull.v1.XmlPullParserException: PI must not start with xml (position:unknown ?@1:5 in java.io.InputStreamReader@63e5ba24) 
> 	at org.kxml2.io.KXmlParser.exception(Unknown Source)
> 	at org.kxml2.io.KXmlParser.error(Unknown Source)
> 	at org.kxml2.io.KXmlParser.parseLegacy(Unknown Source)
> 	at org.kxml2.io.KXmlParser.nextImpl(Unknown Source)
> 	at org.kxml2.io.KXmlParser.next(Unknown Source)
> 	at com.android.layoutlib.bridge.android.BridgeXmlBlockParser.next(BridgeXmlBlockParser.java:267)
> 	at android.graphics.drawable.Drawable.createFromXml(Drawable.java:796)
> 	at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:208)
> 	at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:774)
> 	at android.view.View.<init>(View.java:2785)
> 	at android.view.View.<init>(View.java:2722)
> 	at android.view.ViewGroup.<init>(ViewGroup.java:379)
> 	at android.widget.RelativeLayout.<init>(RelativeLayout.java:174)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
> 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> 	at android.view.LayoutInflater.createView(LayoutInflater.java:586)
> 	at android.view.BridgeInflater.onCreateView(BridgeInflater.java:86)
> 	at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
> 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
> 	at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:131)
> 	at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
> 	at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
> 	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:321)
> 	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:324)
> 	at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
> 	at mono.android.DesignerSession.load(DesignerSession.java:166)
> 	at mono.android.DesignerSession.processMessage(DesignerSession.java:605)
> 	at mono.android.MessageListener.executeMessage(MessageListener.java:87)
> 	at mono.android.MessageListener$Runner.run(MessageListener.java:44)
> 	at java.lang.Thread.run(Thread.java:695)
> 
> ERROR: Bridge [null] Failed to parse file /Volumes/ramdisk/ShapeDrawableBackground/AndroidApp1/Resources/drawable/shape_one.xml


## Expected results / "workarounds"

- The same combination of `shape_one.xml` and `Main.axml` is rendered correctly by the Android designer in Eclipse.

- Running the test case on device or emulator produces the correct result: the background is cyan rather than black. (as mentioned in comment 1)

- Removing the `<?xml version="1.0" encoding="utf-8"?>` line from `shape_one.xml` stops the problem. (as mentioned in comment 3)


## Version information

Mac OS X 10.9.5

=== Xamarin Studio ===

Version 5.7 (build 660)
Installation UUID: 2c0ea975-8f73-4920-8414-3e9ae359fbf4
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/macuser/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /Users/macuser
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Build Information ===

Release ID: 507000660
Git revision: 6a74f9bdb90d9415b597064d815c9be38b401fee
Build date: 2014-12-18 00:38:00-05
Xamarin addins: 57be0f5e1433cb58b70ea9b52e9dc77ad791be40
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-05 15:02:31 UTC
Created attachment 9244 [details]
IDE log files
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-05 15:04:48 UTC
To keep the tally of customers reporting the issue up to date, here's the latest related Desk case:
https://xamarin.desk.com/agent/case/91097
Comment 8 Abhishek 2015-12-02 14:33:09 UTC
I have tried this issue and able to reproduce this issue at my end.

I have followed the steps given in the comment 5.

Screencast: http://www.screencast.com/t/JoeLaoSG9jzp
Ide Log: https://gist.github.com/Abhishekk360/fdb2e16d38725ca16d6f
Android Tool Log: https://gist.github.com/Abhishekk360/1436865b3b3135f2ce28
Adb logcat: https://gist.github.com/Abhishekk360/72a0bc5422a4db607d6e

Environment Info:

=== Xamarin Studio ===

Version 5.10.2 (build 14)
Installation UUID: 93e693b0-b53d-40f4-b29c-b61ff5cbe892
Runtime:
	Mono 4.2.1 (explicit/bb6d8b9)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010115

=== Xamarin.Profiler ===

Version: 0.23.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 6.0.0.40 (Enterprise Edition)
Android SDK: /Users/xamarin23/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.1
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.Mac ===

Not Installed

=== Xamarin.iOS ===

Version: 9.2.2.20 (Enterprise Edition)
Hash: e0c879e
Branch: master
Build date: 2015-12-01 18:29:43-0500

=== Build Information ===

Release ID: 510020014
Git revision: a05150ff9af3205952d9f2ab4417f8036205c035
Build date: 2015-11-30 15:11:41-05
Xamarin addins: e89ff179a2cbe19b4eca4ac3859248e25c20225a
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin 800BC.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 9 softlion 2017-09-01 06:54:45 UTC
Closing as using Android Studio designer with XamarIdea is much much faster and works fine