2014-06-26 40 views
11

我正在測試我的Nexus 5上的Android L Preview。我的應用程序出現問題。Android L忽略了可繪製背景的形狀

我有一些TextViews背景設定:

android:background="@drawable/rounded_textview" 

而 「rounded_textview」 只是形狀。它的效果很好,低於< = 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> 

在Android L Developer Preview後臺被忽略。我所有的TextView都是透明的。 任何想法我做錯了什麼?

+0

此bug已報道了Android的開發者預覽版的bug跟蹤系統,並希望能在最終發佈前固定Android L: https://code.google.com/p/android-developer-preview/issues/detail?id=177 – BladeCoder

回答

36

我發現,在選擇和項目的標籤包裝的形狀使它工作

<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> 
+0

是的。這解決了我的問題。 – adek

+0

很好的回覆,謝謝! – CyberDandy

+2

感謝您的解決方法,但是我仍然希望Google能夠在Android L官方發佈之前解決此問題。有沒有人在官方的Android bug跟蹤器上報告過這個問題? – BladeCoder

0

只要使用android:radius,不要使用每個角落選項。 我有同樣的問題,但我能用這種方式解決問題。

<?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> 
+0

是的。但這僅僅是一個例子。我想爲每個角使用不同的半徑。但是下面的答案正在處理我的案子。把你的東西放在。 – adek