应用程序在棒棒糖前崩溃

时间:2017-06-29 10:07:48

标签: android android-layout

可能是一个愚蠢的问题,但真的在谷歌寻找2小时。 实际上我的应用程序在前棒棒糖中崩溃但在其他版本中运行良好。以下是崩溃报告。

FATAL EXCEPTION: main
                                                                             android.view.InflateException: Binary XML file line #15: Error inflating class Button
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
                                                                                 at .MvpFragment.onCreateView(MvpFragment.java:59)
                                                                                 at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                 at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                 at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                 at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                 at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                 at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                 at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                                                                                 at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
                                                                                 at android.os.Handler.handleCallback(Handler.java:730)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                 at android.os.Looper.loop(Looper.java:176)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5419)
                                                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                 at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
                                                                                 at dalvik.system.NativeStart.main(Native Method)
                                                                              Caused by: android.content.res.Resources$NotFoundException: File res/drawable/custom_button_selected.xml from drawable resource ID #0x7f0200a4

我使用自定义背景作为按钮,如下所示:

<Button
    android:id="@+id/btnCompleted"
    android:layout_weight="1"
    android:layout_gravity="left"
    android:text="Completed"
    android:textColor="@android:color/white"
    android:background="@drawable/custom_button_selected"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

custom_button_selected.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="?attr/icon_color"
                android:endColor="?attr/icon_color"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="@color/transparent_color8" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item android:state_focused="true" >
        <shape>
            <gradient
                android:endColor="?attr/icon_color"
                android:startColor="?attr/icon_color"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="@color/transparent_color8" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>

    <item>
        <shape>
            <gradient
                android:startColor="?attr/icon_color"
                android:endColor="?attr/icon_color"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="@color/transparent_color8" />
            <corners
                android:radius="2dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>

2 个答案:

答案 0 :(得分:0)

StateListDrawable可用于更改按钮的状态(按下,聚焦......),如果您打算使用custom_button_selected.xml作为背景来改变按钮的状态,那么您将失踪drawable内部selector内容item<item android:state_pressed="true" android:drawable="@color/transparent_color8"> .... </item>。像这样:

Select * from ndc group by order_id; - 或者你想用的任何颜色

答案 1 :(得分:0)

android {defaultConfig {vectorDrawables.useSupportLibrary = true}}