작성
·
155
0
<!-- activity_webView.xml -->
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="user"
type="com. ~" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
<fragment
android:id="@+id/nav_host_fragment_activity_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
로 특정 액티비티 전용 xml파일에 입력을 하였습니다(Android studio에서 선택하면 기본적으로 생성해주는 Bottom navigation 프로젝트의 코드를 따왔습니다).
그런데 기본 프로젝트와는 다르게, 위처럼 직접 코드를 넣어주니까 Bottom navigation 바가 미리보기에 보이지 않습니다. fragment는 잘 보이는데 Bottom navigation만 보이질 않네요.
<실제 모습>
이건 분명 @menu/bottom_nav_menu의 문제일것이라 생각하고 문제점을 찾아보려 했으나 보이질 않았습니다. 애초에 너무 자체가 간단한 코드의 복붙이어서 문제가 없어 보입니다.
<!-- menu/bottom_nav_menu.xml -->
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_home" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_dashboard" />
<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/title_notifications" />
</menu>
혹시 무엇이 문제일지, 이런 경험이 있는 분이 계시다면 조언 부탁드리겠습니다
답변 1
0
안녕하세요, 인프런 AI 인턴입니다.
장산님, 바텀네비게이션 요소가 안보이는 이슈는 몇 가지 일반적인 원인들로 인해 발생할 수 있습니다. 제공해주신 정보를 바타냅니다.
XML 파일상의 오류나 누락: activity_webView.xml
파일과 bottom_nav_menu.xml
파일 모두 올바르게 작성된 것처럼 보입니다. 말씀하신대로, 이 부분에서는 문제가 없어 보입니다.
리소스 파일의 문제: @drawable/ic_home_black_24dp
, @drawable/ic_dashboard_black_24dp
, @drawable/ic_notifications_black_24dp
등의 리소스 파일이 존재하는지 혹은 경로가 올바른지 확인해보시기 바랍니다. 리소스 파일의 부재나 경로 문제도 UI 요소가 제대로 표시되지 않을 수 있습니다.
스타일/테마 설정 문제: Android 앱에서 사용하고 있는 테마나 스타일 설정에 따라서도 UI 요소가 보이지 않을 수 있습니다. 예를 들어, 바텀네비게이션 바의 배경색과 항목들의 색상이 너무 유사하여 구분이 되지 않거나, 앱 테마가 요소를 숨기는 형태로 설정되어 있을 가능성이 있습니다.
IDE의 렌더링 문제: Android Studio의 미리보기에서 요소가 제대로 표시되지 않는 경우가 있으며, 이는 대부분 IDE의 렌더링 문제일 가능성이 높습니다. 이를 해결하기 위해서는 Android Studio를 재시작하거나, 캐시를 지우고 다시 빌드해보는 것이 좋습니다.
누락된 속성 또는 오타: XML 파일 내에 오타가 없는지도 다시 한번 확인해보세요. 때로는 작은 오타나 누락된 속성이 문제의 원인이 될 수 있습니다.
비록 제공해 주신 정보에 직접적으로 귀하의 문제를 해결할 수 있는 명확한 해결책이 포함되어 있지 않지만, 위에서 설명한 일반적인 확인 사항들을 바탕으로 문제를 진단해보시길 바랍니다. 추가적으로, 문제 해결이 어려운 경우 Android 개발 커뮤니티나 Stack Overflow에 질문을 올려 도움을 요청하는 것도 좋은 방법입니다.