0

My binary xml returns error when being by inflated in Android 4.4. It's ok if I running in Android 5.0+.

I can't figure out what's causing the error. I'm not using any jpg/png for my drawable.

Here's the XML:

custom_number_picker.xml

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="128dp"
    android:minHeight="32dp">
    <ImageButton
        android:id="@+id/button_sale_decrease"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:minWidth="40dp"
        android:minHeight="32dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin_0_5"
        android:layout_marginTop="@dimen/activity_vertical_margin_0_5"
        android:layout_marginBottom="@dimen/activity_vertical_margin_0_5"
        android:background="@drawable/custom_number_picker_decrease"
        android:src="@drawable/ic_remove"
        android:tint="@android:color/white" />
    <EditText
        android:id="@+id/edit_sale_number"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.5"
        android:minWidth="64dp"
        android:minHeight="32dp"
        android:layout_marginTop="@dimen/activity_vertical_margin_0_5"
        android:layout_marginBottom="@dimen/activity_vertical_margin_0_5"
        android:background="@drawable/custom_number_picker_middle"
        android:gravity="center"
        android:cursorVisible="false"
        android:inputType="number"
        android:text="0"/>
    <ImageButton
        android:id="@+id/button_sale_increase"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:minWidth="40dp"
        android:minHeight="32dp"
        android:layout_marginRight="@dimen/activity_horizontal_margin_0_5"
        android:layout_marginTop="@dimen/activity_vertical_margin_0_5"
        android:layout_marginBottom="@dimen/activity_vertical_margin_0_5"
        android:background="@drawable/custom_number_picker_increase"
        android:src="@drawable/ic_add"
        android:tint="@android:color/white"/>
</merge>

ic_add.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>

custom_number_picker_middle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/white"/>
    <stroke android:color="@color/homefren_blue_light_clicked" android:width="1dp"/>
</shape>
Eldwin Eldwin
  • 1,084
  • 2
  • 11
  • 29

2 Answers2

1

If you are using Vector Drawables with ImageView or its subclasses (including ImageButton), and you want to support pre-Lollipop devices, you need to use the app:srcCompat attribute instead of the android:src attribute to specify the image. So change this:

android:src="@drawable/ic_add"

to this:

app:srcCompat="@drawable/ic_add"

anywhere you're using a vector drawable.

You may also have to modify your build.gradle file, by adding this line:

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

This goes in your app-level gradle file.

Ben P.
  • 52,661
  • 6
  • 95
  • 123
0

It's because you use vector. Vector isn't enable on kitkat. See this post : Using android vector Drawables on pre Lollipop crash

filol
  • 1,669
  • 1
  • 15
  • 38