最近在研究自定義相機,準備用TextureView投影相機的畫面。并且參考了他人的demo后,可以成功實作。
但是在整合進自己的專案時,TextureView的使用卻出現了問題
XML檔案:
<TextureView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ll_bottom" />
報錯原因:
android.view.InflateException: Binary XML file line #77: Binary XML file line #77: Error inflating class android.view.TextureView
Caused by: android.view.InflateException: Binary XML file line #77: Error inflating class android.view.TextureView
Caused by: java.lang.UnsupportedOperationException: TextureView doesn't support displaying a background drawable
檢查后發現demo的環境是25.0.2 我是配的專案的環境是27.1.1 不知道是因為版本問題導致的 還是別的原因 求助
uj5u.com熱心網友回復:
android7.0以后 TextureView 不支持背景設定吧uj5u.com熱心網友回復:
在XML里面沒有設定背景 上級layout也沒有設定背景 參考沒有背景的style也無效uj5u.com熱心網友回復:
我也遇到過,是Activity的theme問題,theme得是Theme.AppCompat的主題,我改為android:theme="@style/Theme.AppCompat.NoActionBar" 就可以了。uj5u.com熱心網友回復:
只要主題里沒有設定背景就行,檢查主題轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/23785.html
標籤:Android
