0

Couple days i'm confused with error Caused by: android.view.InflateException: Binary XML file line #46: Error inflating class Button, i tried to find out what happen but no luck, in similar problem i found in stackoverflow but i think my case is little bit difference,,

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo
android.view.InflateException: Binary XML file line #46: Error inflating class Button
Caused by: android.content.res.Resources$NotFoundException: 
**File res/drawable/btn_primary.xml from drawable resource ID #0x7f020058**

then i realize, my file btn_primary_dark.xml and another drawable xml caused this error, everything works fine on Lollipop and up, but not at API before 21 like kitkat or JB,,in stack trace write not found resource but i have my xml file, i have file on drawable folder

btn_primary.xml
btn_primary_dark.xml
btn_light.xml
..

and folder drawable-v21

btn_primary.xml
btn_primary_dark.xml
btn_light.xml
..

btn_primary.xml in drawable folder

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <corners android:radius="3dip" />
            <solid android:color="?colorControlHighlight" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="3dip" />
            <solid android:color="@color/primary" />
        </shape>
    </item>
</selector>

btn_primary.xml in drawable-v21 folder

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?colorControlHighlight">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="3dip" />
            <solid android:color="@color/primary" />
        </shape>
    </item>
</ripple>

please if someone ever has same issue, i want to know how i solve this.. thanks for your help.

1

1 Answer 1

2

i figure out something, turns out error because xml pre lollipop doesn't recognize <solid android:color="?colorControlHighlight" /> so i just change with <solid android:color="@color/accent" />

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <corners android:radius="3dip" />
            <solid android:color="@color/accent" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="3dip" />
            <solid android:color="@color/primary" />
        </shape>
    </item>
</selector>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.