类型参数T具有不兼容的上限:View和BottomNavigationViewEx

时间:2018-12-04 19:31:32

标签: android

我试图使缓存/重新启动无效,并重命名xml文件,但没有成功。当我尝试使用findViewById方法设置变量时出现错误。另外,通过在此之前添加一个隐式(BottomNaviagtionViewEx),我收到以下错误:不可转换类型;无法将“ android.view.View”转换为“ com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx”。

这是我的xml代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="layout.index.HomeFeed">

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/containter"
        android:layout_above="@+id/bottomNavLayout">

    </android.support.v4.view.ViewPager>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:id="@+id/bottomNavLayout">

        <include layout="@layout/layout_bottom_navigation_view">

        </include>
    </RelativeLayout>

</RelativeLayout>

活动的Java文件

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx;

public class test extends AppCompatActivity {

    BottomNavigationViewEx bottomBar;
    Menu bottomBarMenu;
    MenuItem bottomBarMenuItem;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        bottomBar = (BottomNavigationViewEx) findViewById(R.id.bottomNavBar);
    }
}

顶级gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用级gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.test.edward.test"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 2
        versionName "1.0.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation 'com.android.support:support-v4:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-database:16.0.5'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
    implementation 'com.github.ittianyu:BottomNavigationViewEx:1.2.4'
    implementation "com.android.support:design:27.1.1"
}

apply plugin: 'com.google.gms.google-services'

任何帮助将不胜感激, 谢谢

编辑:这是我的layout_bottom_navigation_view.xml文件

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true">

        <com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/bottomNavViewBar"
            android:background="@drawable/border_bottom"
            app:menu="@menu/bottom_navigation_menu">

        </com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx>

    </RelativeLayout>

</merge>

但是,即使我直接将BottomNavigationViewEx添加到主活动中,也不会消除该错误。 谢谢

1 个答案:

答案 0 :(得分:0)

已解决: 已更改

compileSdkVersion 27

targetSdkVersion 27

compileSdkVersion 28

targetSdkVersion 28

并从应用程序级别gradle中删除了以下几行:

implementation "com.android.support:design:27.1.1"
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'