我在应用程序中使用简单的ImageView。

如下

 <ImageView
            android:id="@+id/imvTripArrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:contentDescription="@null"
            android:src="@drawable/ic_arrow_roundtrip_white" />


我为此ImageView设置的图标是白色。
但有时它显示为黑色而不是白色。(仅在设备Nexus5 API 21中)

以下是我的活动中使用的主题。

<style name="NoTitleBarCustom" parent="Theme.AppCompat.NoActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowBackground">@android:color/black</item>
        <item name="android:textColorPrimary">@android:color/white</item><!-- tool bar text color-->
        <item name="colorPrimary">@android:color/white</item> <!-- tool bar-->
        <item name="colorPrimaryDark">@android:color/black</item> <!-- notification bar-->
        <item name="colorAccent">@android:color/white</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>


此问题出现在我的应用程序的许多ImageView中。
我对此问题进行了很多搜索,但未找到任何解决方案。有人请帮助!!!

最佳答案

使用AppCompatImageView而不是ImageView。



<android.support.v7.widget.AppCompatImageView
        android:id="@+id/imvTripArrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:contentDescription="@null"
        app:srcCompat="@drawable/ic_arrow_roundtrip_white"
        app:tint="#fff/>

           





在gradle中添加“ vectorDrawables.useSupportLibrary = true”。



android {
    compileSdkVersion 28
    defaultConfig {
        .....
        vectorDrawables.useSupportLibrary = true
    }

关于android - 有时ImageView出现黑色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54803932/

10-12 00:28
查看更多