[英]How to fix distorted R.drawable icons when updating app from API 8 to API 26+
我正在嘗試恢復和修改一個 10 多年歷史的應用程序(Android 2.2、4.1),該應用程序當時顯示和運行良好,但現在,當安裝在 Android 8.1 設備上時,它會出現以下奇怪的視覺問題:
在 API 8/16 它按預期顯示R.drawable圖標/按鈕:
但是在 API 26/29 上,它以這種方式顯示相同(無意):
負責顯示的 main.xml 部分是:
<!-- horizontal row of 3 buttons (prev, pause/play, next) -->
<LinearLayout
android:id="@+id/prev_pauseplay_next_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<com.susu.mylib.core.MyButton
android:id="@+id/btn_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_media_previous"
/>
<LinearLayout
android:id="@+id/ll_pause_or_play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.susu.mylib.core.MyButton
android:id="@+id/btn_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_media_pause"
android:layout_marginLeft="36dp"
android:layout_marginRight="36dp"
/>
<com.susu.mylib.core.MyButton
android:id="@+id/btn_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_media_play"
android:layout_marginLeft="36dp"
android:layout_marginRight="36dp"
android:visibility="gone" />
</LinearLayout> <!-- end ll_pause_or_play_button -->
<com.susu.mylib.core.MyButton
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_media_next"
/>
</LinearLayout> <!-- end prev_pauseplay_next_buttons -->
知道為什么會發生這種情況以及如何解決這個問題嗎?
另外,哪個 Android SDK 庫或 jar 包含這些圖像?
采用
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
/>
而不是背景
或將舊的可繪制對象包裝成:
res/drawable/wrapped_ic_media_pause.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@android:drawable/ic_media_pause"
android:gravity="center"
height="24dp"
width="24dp"
/>
</layer-list>
然后在你的 xml 中使用@drawable/wrapped_ic_media_pause
而不是@android:drawable/ic_media_pause
如果需要指定高度和寬度(否則圖標可能很小)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.