UnsupportedOperationException: Failed to resolve attribute at index 13:TypedValue{t=0x2/d=0x7f03018

bug描述:
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f03018e a=7}

原因:
構造佈局填充器對象LayoutInflater.from(context.getApplicationContext())時,傳入的上下文對象是全局的,

而佈局中使用了新屬性(類似selectableItemBackground),全局的上下文就會不支持,程序就會奔潰

-----------------------------------------------------------------------------------------------------------------------------

佈局中使用了android:background="?attr/selectableItemBackground"

 <TextView
        android:background="?attr/selectableItemBackground"
        android:id="@+id/tv_city"
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:gravity="center_vertical"
        android:paddingLeft="18dp"
        android:text="深圳"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章