【问题标题】:Error inflating class android.support.v7.widget.SearchView膨胀类 android.support.v7.widget.SearchView 时出错
【发布时间】:2017-07-29 03:38:58
【问题描述】:

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

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

这是我得到的错误。

android.view.InflateException:二进制 XML 文件第 10 行:二进制 XML 文件第 10 行:膨胀类 android.support.v7.widget.SearchView 时出错

这是我的 .xml。 (在线性布局中)

<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"/>

下面是我的 Manifest 的一部分

<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'
}

【问题讨论】:

  • 我们发布的代码似乎没有问题。我试过了。效果很好。

标签: android xml searchview


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    替换

    android.support.v7.widget.SearchView
    

    androidx.appcompat.widget.SearchView
    

    它会起作用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-06
      • 2014-10-18
      • 2015-01-06
      • 2014-12-21
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多