質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

0回答

1664閲覧

Unresolved reference: fabというエラーが直せないです。

masato01

総合スコア11

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2021/08/20 04:57

解決したいこと

todoアプリを作っています。
デザインを始めたのですがエラーが出てしまいました。

発生している問題・エラー

Unresolved reference: fab

fabというのはidです。

それとfabボタンに警告マークがありました。
Missing contentDescription attribute on image Non-textual widgets like ImageViews and ImageButtons should use the contentDescription attribute to specify a textual description of the widget such that screen readers and other accessibility tools can adequately describe the user interface. Note that elements in application screens that are purely decorative and do not provide any content or enable a user action should not have accessibility content descriptions. In this case, just suppress the lint warning with a tools:ignore="ContentDescription" attribute. Note that for text fields, you should not set both the hint and the contentDescription attributes since the hint will never be shown. Just set the hint. See https://developer.android.com/guide/topics/ui/accessibility/apps#special-cases

該当するソースコード

MainFragment.kt

1package com.example.todo 2 3import android.os.Bundle 4import android.view.View 5import androidx.fragment.app.Fragment 6import androidx.fragment.app.FragmentContainer 7import androidx.fragment.app.viewModels 8import androidx.navigation.Navigation.findNavController 9import androidx.navigation.fragment.findNavController 10import com.example.todo.databinding.MainFragmentBinding 11import dagger.hilt.android.AndroidEntryPoint 12 13 14@AndroidEntryPoint 15class MainFragment: Fragment(R.layout.activity_main) { 16 private val vm: MainViewMotel by viewModels() 17 18 // ここから下を追加 19 private var _binding: MainFragmentBinding? = null 20 private val binding: MainFragmentBinding get() = _binding!! 21 22 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 23 super.onViewCreated(view, savedInstanceState) 24 this._binding = MainFragmentBinding.bind(view) 25 26 binding.fab.setOnClickListener { 27 findNavController().navigate(R.id.action_mainFragment2_to_createtodoFragment3) 28 } 29 30 } 31 32 override fun onDestroyView() { 33 super.onDestroyView() 34 this._binding = null 35 } 36}

activity_main.xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 9 <com.google.android.material.floatingactionbutton.FloatingActionButton 10 android:id="@+id/fab" 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:layout_marginStart="342dp" 14 android:layout_marginLeft="342dp" 15 android:layout_marginTop="658dp" 16 android:layout_marginEnd="13dp" 17 android:layout_marginRight="13dp" 18 android:layout_marginBottom="13dp" 19 android:clickable="true" 20 app:layout_constraintBottom_toBottomOf="parent" 21 app:layout_constraintEnd_toEndOf="parent" 22 app:layout_constraintStart_toStartOf="parent" 23 app:layout_constraintTop_toTopOf="parent" 24 app:srcCompat="@drawable/ic_baseline_add_24" /> 25</androidx.constraintlayout.widget.ConstraintLayout>

build.gradle

1plugins { 2 id 'com.android.application' 3 id 'kotlin-android' 4 id 'kotlin-kapt' 5 id 'dagger.hilt.android.plugin' 6 7} 8 9 10 11android { 12 compileSdkVersion 30 13 buildToolsVersion "30.0.3" 14 15 defaultConfig { 16 applicationId "com.example.todo" 17 minSdkVersion 16 18 targetSdkVersion 30 19 versionCode 1 20 versionName "1.0" 21 22 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 23 24 vectorDrawables.useSupportLibrary = true 25 } 26 27 buildTypes { 28 release { 29 minifyEnabled false 30 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 31 } 32 } 33 compileOptions { 34 sourceCompatibility JavaVersion.VERSION_1_8 35 targetCompatibility JavaVersion.VERSION_1_8 36 } 37 kotlinOptions { 38 jvmTarget = '1.8' 39 } 40 41 buildFeatures { 42 viewBinding true 43 } 44 45} 46 47dependencies { 48 49 50 implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 51 implementation 'androidx.core:core-ktx:1.5.0' 52 implementation 'androidx.appcompat:appcompat:1.3.0' 53 implementation 'com.google.android.material:material:1.3.0' 54 implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 55 implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' 56 implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' 57 testImplementation 'junit:junit:4.+' 58 androidTestImplementation 'androidx.test.ext:junit:1.1.2' 59 androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 60 61 62 //Navigation 63 implementation("androidx.navigation:navigation-fragment-ktx:2.3.5") 64 implementation("androidx.navigation:navigation-ui-ktx:2.3.5") 65 66 //Room 67 def room_version = "2.3.0" 68 implementation "androidx.room:room-runtime:$room_version" 69 annotationProcessor "androidx.room:room-compiler:$room_version" 70 kapt "androidx.room:room-compiler:$room_version" 71 implementation "androidx.room:room-runtime:$room_version" 72 implementation "androidx.room:room-ktx:$room_version" 73 74 //Hilt 75 implementation "com.google.dagger:hilt-android:2.28-alpha" 76 kapt "com.google.dagger:hilt-android-compiler:2.28-alpha" 77 78 //activity 79 implementation "androidx.activity:activity-ktx:1.1.0" 80 81} 82

自分で試したこと

このサイト(https://stackoverflow.com/questions/41407811/android-vectordrawables-usesupportlibrary-true-is-stopping-app) を見てbuild.gradleファイルに追加

vectorDrawables.useSupportLibrary = true

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2021/08/24 23:53

MainFragment なのに R.layout.activity_main なのが謎だし、さらに MainFragmentBinding に bind してるのがもっと謎ですね…。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問