未解决的参考:FragmentTitleBinding

Android开发

我想在我的Android应用程序中使用片段,但是我无法导入FragmentTitleBinding片段类,因此我尝试了互联网上所有可能的解决方案

  1. 我检查了xml文件中的布局标签
  2. 我编辑build.gradle文件
  3. 同步专案
import com.example.android.navigation.databinding.FragmentTitleBinding

class TitleFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                          savedInstanceState: Bundle?): View? {
    val binding : com.example.android.navigation.databinding.FragmentTitleBinding=
            DataBindingUtil.inflate(inflater,R.layout.fragment_title,container,false)
    return binding.root;
    }
}

片段XML

 <?xml version="1.0" encoding="utf-8"?>

<layout 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"
    tools:context="com.example.android.navigation.TitleFragment">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/titleConstraint"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/playButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/horizontal_margin"
            android:layout_marginEnd="@dimen/horizontal_margin"
            android:paddingStart="@dimen/button_padding"
            android:paddingEnd="@dimen/button_padding"
            android:text="Play"
            android:textColor="@color/colorAccent"
            android:textSize="@dimen/button_text_size"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/titleImage" />

            <ImageView
            android:id="@+id/titleImage"
            android:layout_width="0dp"
            android:layout_height="@dimen/image_header_height"
            android:layout_marginStart="@dimen/horizontal_margin"
            android:layout_marginEnd="@dimen/horizontal_margin"
            android:scaleType="fitCenter"
            app:layout_constraintBottom_toTopOf="@+id/playButton"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/android_trivia" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

build.gradle

  apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    dataBinding {
        enabled = true
    }
    defaultConfig {
        applicationId 'com.example.android.navigation'
        minSdkVersion 19
        targetSdkVersion 28
        vectorDrawables.useSupportLibrary = true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    buildToolsVersion = '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$version_kotlin"
    // Constraint Layout
    implementation "androidx.constraintlayout:constraintlayout:$version_constraint_layout"
    // Core
    implementation "androidx.core:core:$version_core"
    // Material Design
    implementation "com.google.android.material:material:$version_material"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    kapt 'com.android.databinding:compiler:3.3.0'
}
kapt {
    generateStubs = true
}

我想解决,FragmentTitleBinding但是给出了错误的未解决参考

南大Z

由于数据绑定的执行方式类似于注释处理器,因此您必须清理项目,然后再次进行重建。如果那样不行。尝试以下操作:1.单击文件菜单2.选择“使缓存无效/重新启动”

图片

我希望它能起作用。并且请注意,您的数据绑定类的名称与布局名称相同

更新资料

确保您的依赖项中包含这些

kapt "androidx.lifecycle:lifecycle-compiler:2.0.0"

android{
dataBinding {
        enabled = true
    }
}

您还需要检查SDK工具中的存储库 SDK工具

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章