質問編集履歴

1

Activiについて追記しました

2020/11/21 09:45

投稿

userUser
userUser

スコア0

test CHANGED
File without changes
test CHANGED
@@ -334,6 +334,138 @@
334
334
 
335
335
  ```
336
336
 
337
+
338
+
339
+ ### 該当のソースコード
340
+
341
+
342
+
343
+ ```kotlin
344
+
345
+ //Activity
346
+
347
+ import android.os.Bundle
348
+
349
+ import com.google.android.material.bottomnavigation.BottomNavigationView
350
+
351
+ import androidx.appcompat.app.AppCompatActivity
352
+
353
+ import androidx.navigation.findNavController
354
+
355
+ import androidx.navigation.ui.setupWithNavController
356
+
357
+
358
+
359
+ class TopActivity : AppCompatActivity() {
360
+
361
+ override fun onCreate(savedInstanceState: Bundle?) {
362
+
363
+ super.onCreate(savedInstanceState)
364
+
365
+ setContentView(R.layout.top_activity)
366
+
367
+
368
+
369
+ val navView: BottomNavigationView = findViewById(R.id.nav_view)
370
+
371
+
372
+
373
+ val navController = findNavController(R.id.nav_host_fragment)
374
+
375
+ // Passing each menu ID as a set of Ids because each
376
+
377
+ // menu should be considered as top level destinations.
378
+
379
+
380
+
381
+ navView.setupWithNavController(navController)
382
+
383
+ }
384
+
385
+ }
386
+
387
+ ```
388
+
389
+
390
+
391
+ ### 該当のソースコード
392
+
393
+ ```xml
394
+
395
+ //Activityのxml
396
+
397
+ <?xml version="1.0" encoding="utf-8"?>
398
+
399
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
400
+
401
+ xmlns:app="http://schemas.android.com/apk/res-auto"
402
+
403
+ android:id="@+id/container"
404
+
405
+ android:layout_width="match_parent"
406
+
407
+ android:layout_height="match_parent">
408
+
409
+
410
+
411
+ <com.google.android.material.bottomnavigation.BottomNavigationView
412
+
413
+ android:id="@+id/nav_view"
414
+
415
+ app:labelVisibilityMode="labeled"
416
+
417
+ android:layout_width="0dp"
418
+
419
+ android:layout_height="wrap_content"
420
+
421
+ android:layout_marginStart="0dp"
422
+
423
+ android:layout_marginEnd="0dp"
424
+
425
+ android:background="?android:attr/windowBackground"
426
+
427
+ app:layout_constraintBottom_toBottomOf="@+id/nav_host_fragment"
428
+
429
+ app:layout_constraintLeft_toLeftOf="parent"
430
+
431
+ app:layout_constraintRight_toRightOf="parent"
432
+
433
+ app:menu="@menu/bottom_nav_menu" />
434
+
435
+
436
+
437
+ <fragment
438
+
439
+ android:id="@+id/nav_host_fragment"
440
+
441
+ android:name="androidx.navigation.fragment.NavHostFragment"
442
+
443
+ android:layout_width="match_parent"
444
+
445
+ android:layout_height="match_parent"
446
+
447
+ app:defaultNavHost="true"
448
+
449
+ app:layout_constraintBottom_toTopOf="@id/nav_view"
450
+
451
+ app:layout_constraintLeft_toLeftOf="parent"
452
+
453
+ app:layout_constraintRight_toRightOf="parent"
454
+
455
+ app:layout_constraintTop_toTopOf="parent"
456
+
457
+ app:navGraph="@navigation/mobile_navigation" />
458
+
459
+
460
+
461
+ </androidx.constraintlayout.widget.ConstraintLayout>
462
+
463
+ ```
464
+
465
+
466
+
467
+
468
+
337
469
  ### 試したこと
338
470
 
339
471
  最初Layoutmanagerを忘れていたので追加してみましたが、やはり同じエラーの表示がありました