Reputation: 1
I want to give to a TextView a background. This background (classement_background.xml) is a drawable located in res/drawable.
Here's its code :
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape="ring"
xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:startColor="#ff648add"
android:endColor="#ff3656dd"
android:type="linear"
/>
</shape>
In the render window of the layout file, my background is set. (Android studio)
But for some reason, this drawable is not there anymore on a genymotion emulator nor an actual device.
I've been trying quite a few things (like making sure it isn't the first element in the drawable folder), but I can't figure out what's going on. Any thoughts ?
Here's the code from the textview itself : `
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E2"
android:id="@+id/classement"
android:layout_below="@+id/firstname"
android:layout_centerHorizontal="true"
android:textSize="85dp"
android:layout_marginTop="15dp"
android:padding="30dp"
android:background="@drawable/classement_background"
android:textColor="@android:color/white"/>`
Upvotes: 0
Views: 2106
Reputation: 758
Maybe I will post something, that helped me. My backgroung id 1920x1920 pixels and display 1920x1080, so different size shouldn't be the problem.
I suppose that you have your background putted in some resource "drawable" folder (for example in drawable-hdpi) in Eclipse IDE. I had that either and on real device (Sony Xperia Z2) I haven't seen nothing.
Short answer:
I had to add my desired backgroung to every single drawable folder - drawable-ldpi, drawable-xxhdpi, ...
After this strange operation Sony finally recognized my backroung and accepted it. :-)
I hope this will help somebody.
Upvotes: 0
Reputation: 1
Try to set android:thickness for the shape. Maybe android doesn't provide a default thickness for the xml drawables.
Upvotes: 0
Reputation: 589
Add the android:useLevel="false" attribute to your shape tag. My IDE didn't display your shape in its preview window until I added it.
According to the docs:
android:useLevel
Boolean. "true" if this is used as a LevelListDrawable. This should normally be "false" or your shape may not appear.
Upvotes: 1