Xml defined shapes do not show up
Recently I've discovered that I can define shapes in an xml file. Until now I was using nine patch images to create custom buttons etc. When I tried with an xml defined shape it didn't worked. None of the shaps, also from stackoverflow which were provided as examples didn't show up. I've seen that someone has already had a similar problem, however eventually it worked on an actual device. Well in my case it didn't.
Here's the navigation_bar.xml I've tried:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF"
android:angle="270"/>
<padding android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
<corners android:radius="8dp" />
and then used in:
<TextView
android:id="@+id/main_navigation_bar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/navigation_bar"/>
The background stays as default/black, nothing is shown.
Am I missing something here? I've also looked at ApiDemos, official documentation and didn't find anything to solve my problem.
Is it better to stay with ni开发者_如何学Gone patch images?
Thanks for the replies.
When tweaking a little with code, I've noticed strange behaviour. My IDE is IntelliJ.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:visible="true"
android:shape="rectangle">
<gradient
android:startColor="#FF89B4EE"
android:endColor="#FF5791E6"
android:type="linear"
android:angle="90"/>
<size
android:height="fill_parent"
android:dfv="fill_parent" />
I made an intentional typo and code compiled. It looks like shape is being ignored or something. Anyone noticed anything similar?
did you try putting the size of the shape? maybe is a dumb question but works for me, i also write the shapes without size and without "shape rectangle"...
something like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FF89B4EE"
android:endColor="#FF5791E6"
android:type="linear"
android:angle="90"/>
</shape>
maybe you can read here a full documentation of android xml shape elements. cheers
Does your navigation_bar.xml have your xml version header at the top? That is:
<?xml version ="1.0" encoding="utf-8"?>
I'm sure you probably do; I don't know about IntelliJ, but Eclipse won't build without it. Never hurts to check the simple solutions, though. :)
精彩评论