Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Grieve
Treehouse Moderator 91,253 Points[SOLVED] I seem to be having trouble getting the background colour to appear on the emulator
Hi all,
I'm having some trouble getting the background colour on the main activity file to appear on the emulator. I use the default Android Studio Emulator and I'm not sure what's happening.
It appears fine in Android preview but as Ben says you can't always trust that. My version of Android Studio doesn't have the colour picker built in. You can pick from a certain set of options or of course, paste the hexadecimal code into text view. Neither method seems to work.
Here's my XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="uk.co.jonniegrieve.stormy.MainActivity"
tools:background="?android:attr/colorMultiSelectHighlight">
<TextView
android:text="100"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/temperatureLabel"
android:textColor="@android:color/white"
android:textSize="150sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/degree"
android:layout_alignTop="@+id/temperatureLabel"
android:layout_toRightOf="@+id/temperatureLabel"
android:layout_toEndOf="@+id/temperatureLabel"
android:id="@+id/imageView"
android:layout_marginTop="50dp"/>
</RelativeLayout>
and my log data.
02/23 17:42:34: Launching app
$ adb shell am start -n "uk.co.jonniegrieve.stormy/uk.co.jonniegrieve.stormy.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 3018 on device emulator-5554
W/System: ClassLoader referenced unknown path: /data/app/uk.co.jonniegrieve.stormy-1/lib/x86
D/MainActivity: Main UI code is running!
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ 02-23 17:42:35.884 3018: 3018 D/ ]
HostConnection::get() New Host Connection established 0xa9f5f180, tid 3018
[ 02-23 17:42:35.885 3018: 3018 W/ ]
Process pipe failed
[ 02-23 17:42:35.909 3018: 3037 D/ ]
HostConnection::get() New Host Connection established 0xa9f5f4c0, tid 3037
I/OpenGLRenderer: Initialized EGL, version 1.4
E/EGL_emulation: tid 3037: eglSurfaceAttrib(1165): error 0x3009 (EGL_BAD_MATCH)
**W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaaa8c580, error=EGL_BAD_MATCH**
V/MainActivity: {json data.... json data....},{"time":1487875200,"p
I/MainActivity: FROM JSON: America/Los_Angeles
D/MainActivity: 9:43 AM
Where I think it is going wrong is this line. Any idea how to fix?
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaaa8c580, error=EGL_BAD_MATCH**
1 Answer
Jonathan Grieve
Treehouse Moderator 91,253 PointsI was able to solve this two-fold.
First, I set the following
tools:background="#fffc9708"
to
android:background="#fffc9708"
in the activity_main.xml file.
Also there appears to be a bit of a quirk in the current version of Android Studio (2.2.3). When you add an image view, to add the degree image the source picker automatically comes up. But I kept finding that the image would not appear in the default emulator. To fix this I had to manually add the image from the property inspector and go through the source that way. So, if you find the picker automatically comes up, try cancelling that and run it through the image view properties. :)