Android L is ignoring shapes as drawable backgroun

2019-03-25 08:50发布

I'm testing Android L Preview on my Nexus 5. I've got problem with my app.

I've got some TextViews with background set:

android:background="@drawable/rounded_textview"

And "rounded_textview" is just shape. It is working great below <=API19.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="3dp">
<solid android:color="#999999"/>
<corners
 android:bottomRightRadius="2dp"
 android:bottomLeftRadius="2dp"
 android:topLeftRadius="2dp"
 android:topRightRadius="2dp"/>
</shape>

On Android L Developer Preview background is ignored. All my TextViews are transparent. Any idea what am I doing wrong?

2条回答
对你真心纯属浪费
2楼-- · 2019-03-25 09:33

I found that wrapping the shape in a selector and item tag made it work

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">

            <solid android:color="@color/gray" />

            <corners
                android:bottomLeftRadius="3dp"
                android:topRightRadius="3dp"
                android:topLeftRadius="3dp"
                android:bottomRightRadius="3dp" />

        </shape>
    </item>
</selector>
查看更多
时光不老,我们不散
3楼-- · 2019-03-25 09:39

Just use android:radius, not use each corner options. I had a same problem, but I was able to solve the problem using this way.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="3dp">
<solid android:color="#999999"/>
  <corners android:radius="2dp"/>
</shape>
查看更多
登录 后发表回答