2016-03-16 15 views
0

我有我的看法是動態變化的android:drawableEnd /右上的TextView沒有出現在SDK 4.1

<?xml version="1.0" encoding="utf-8"?> 
<TextView android:id="@+id/txt_suburb" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/default_ripple_selector" 
    android:clickable="true" 
    android:drawableEnd="@drawable/image_one" 
    android:drawableRight="@drawable/image_one" 
    android:minHeight="20dp" 
    android:orientation="vertical" 
    android:textAppearance="?android:textAppearanceSmall" 
    android:textColor="@color/black" /> 

我動態改變權繪製對象。

textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, chooseImageTwo? 
      R.drawable.image_two: R.drawable.image_one, 0); 

它適用於所有版本,Android版本4.1除外。 (請注意,4.1中最舊的支持版本)。有什麼問題?

+0

嘗試在設置可繪製線後添加textView.requestLayout()和textView.refreshDrawableState()。 –

回答

0

顯然,當XML中有一個drawable時,它將不會被4.1中的API調用覆蓋。但其他所有版本都可以正常工作所以只需刪除下面的可繪製引用

<?xml version="1.0" encoding="utf-8"?> 
<TextView android:id="@+id/txt_suburb" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/default_ripple_selector" 
    android:clickable="true" 
    android:minHeight="20dp" 
    android:orientation="vertical" 
    android:textAppearance="?android:textAppearanceSmall" 
    android:textColor="@color/black" />