小米手機 佈局出現白色邊框,黑色背景等(適配)

前言:eidtText 在小米手機上出現 白色邊框條,在華爲 三星 等手機上都沒有出現這個問題,特地記錄下 適配的問題

這裏寫圖片描述

直接 在搜索 部分出現白色的邊框,查看代碼

<RelativeLayout
        android:id="@+id/et_search_root"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_weight="1"
        android:background="@drawable/shape_search_head_bg"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/et_search"
            android:layout_toLeftOf="@+id/iv_search_delete"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:gravity="center_vertical"
            android:background="@color/transparent"
            android:drawableLeft="@drawable/search_white"
            android:drawablePadding="7dp"
            android:textColorHint="@color/skin_search_font_color"
            android:imeOptions="actionSearch"
            android:paddingLeft="10dp"
            android:maxLines="1"
            android:singleLine="true"
            android:maxLength="15"
            android:ellipsize="end"
            android:textSize="15dp"
            tools:text=""
            android:textColor="@color/skin_common_title"/>

        <LinearLayout
            android:id="@+id/iv_search_delete"
            android:layout_alignParentRight="true"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:orientation="vertical"
            android:gravity="center"
            android:visibility="gone"
            tools:visibility="visible">

            <ImageView
                android:layout_width="19.2dp"
                android:layout_height="19.2dp"
                android:background="@drawable/search_delete"/>

        </LinearLayout>


    </RelativeLayout>

問題 定位 如下 :在 RelativeLayout 的根佈局部分 加載了 shape_search_head_bg 這個 drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="@color/account_line_color" />

    <corners
        android:radius="4dp"/>
</shape>

查看 很正常的一個drawable ,內部填充,圓角。在三星 華爲等手機沒一點問題沒有,但是在紅米 和部分小米手機上就會出現 上圖 的情況,很無奈。

參考 了 適配:EditText背景在部分手機上顯示黑色

發現 在小米手機上需要設置 透明的屬性

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:width="1dp" android:color="@color/transparent" />
    <solid android:color="@color/account_line_color" />

    <corners
        android:radius="4dp"/>
</shape>

增加了一個屬性 : stroke android:width=”1dp” android:color=”@color/transparent”
發現竟然好了,why!!!!!

這裏寫圖片描述

最終的解決方案是 :

在部分手機上莫名其妙的出現 白色 邊框或者 黑色背景色的,都需要 在 不用的屬性 例如
stroke , solid 等直接顏色 變成 透明的就好了。具體原因 需要研究下!

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