小米手机edittext背景框显示为黑色是什么原因?

小米手机edittext背景框显示为黑色是什么原因?

问题描述:
一般情况下,我们会将edittext在xml文件中

    <EditText
                android:id="@+id/et_home_search"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="10dp"
                android:layout_weight="1"
                android:background="@drawable/home_search_shape"
                android:hint="搜索"
                android:padding="10dp"
                android:textColor="#f00"
                android:textSize="10sp" />

对其设置背景所用的xml文件如下


<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="4dp" />
    <stroke android:color="#fff" android:width="1dp"/> 

shape>

然后在真机上测试发现
(1)小米手机背景框为纯黑色.红米手机正常显示
(2)华为,三星、等其他机型正常显示

解决办法,只需一行代码
把edittext设置的背景shap中,加入全透明即可

  
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="4dp" />
    <stroke android:color="#fff" android:width="1dp"/> 

  <solid android:color="#00000000"/>
shape>

如此便完美解决了问题,不信?你试试。

你可能感兴趣的:(小米手机edittext背景框显示为黑色是什么原因?)