android.support.v7.widget.SearchView类膨胀错误

4

我尝试自己解决这个问题,但是无法找到解决方案。stackoverflow上有一个类似的问题,但是其中没有一个答案能帮助我 (Cannot instantiate class android.support.v7.widget.SearchView)。

在另一个应用程序中,搜索功能完美运行。当我尝试在另一个项目中实现它时,问题就出现了。

这是我收到的错误信息。

android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.SearchView

这是我的.xml文件(在LinearLayout中)。

<android.support.v7.widget.SearchView
    android:id="@+id/floating_search_view"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    app:iconifiedByDefault="false"
    app:actionViewClass="android.support.v7.widget.SearchView"
    />

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="true"/>

以下是我的清单的一部分:

接下来是我的清单的一部分

<activity android:name=".robodex.Robodex"
        android:label="Robodex"
        android:launchMode="singleTop"
        >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
            android:resource="@xml/searchable"/>
    </activity>

以下是所有相关依赖项:

android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "it.uniroma1.android"
    minSdkVersion 21
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
testCompile 'junit:junit:4.12'
compile files('libs/pocketsphinx-android-5prealpha-nolib.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.github.arimorty:floatingsearchview:2.0.3'
}

似乎问题不在我们发布的代码上。我尝试过了,它运行得很好。 - Luong Dinh
2个回答

4

替换

android.support.v7.widget.SearchView

使用

androidx.appcompat.widget.SearchView

它会工作。


0

将您的build.gradle中的buildToolsVersion设置为24.0.2,然后查看。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接