Ped*_*ngo 11 navigation android android-studio-3.0 android-jetpack
我无法使用com.google.android.material.bottomnavigation.BottomNavigationView设置导航组件,但它发出错误.
这是我尝试使用的代码
// Setup bottom navigation view
NavigationUI.setupWithNavController(
bottom_navigation_view,
findNavController(R.id.main_nav_host_fragment)
)
Run Code Online (Sandbox Code Playgroud)
当我打开NavigationUI类时,我注意到它只接受旧的android.support.design.widget.BottomNavigationView,但我想使用新的com.google.android.material.bottomnavigation.BottomNavigationView类.有什么想法吗?
我正在使用这些库
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
// Architecture Components
def nav_version = "1.0.0-alpha02"
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
// use -ktx for Kotlin
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
Run Code Online (Sandbox Code Playgroud)
这是我的活动
NavigationUI.setupWithNavController(bottomNavView,
Navigation.findNavController(this, R.id.nav_host_fragment))
Run Code Online (Sandbox Code Playgroud)
这是我的布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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=".ui.main.ActivityMain">
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="@menu/menu_nav_drawer" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.MaterialComponents.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/dimen_16"
android:layout_marginBottom="72dp"
app:fabSize="normal"
tools:srcCompat="@drawable/ic_add_white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
查看导航文档:https://developer.android.com/topic/libraries/architecture/adding-components#navigation截至 2018 年 6 月 29 日。
它说:
Blockquote Navigation 类已经在 androidx.navigation 包中,但目前依赖于支持库 27.1.1 和相关的 Arch 组件版本。未来将发布具有 AndroidX 依赖项的 Navigation 版本。
我想现在您别无选择,只能等待导航包的“未来”版本。
目前,按照 @Levi Albuquerque 的建议,您需要使用com.android.support:design:28.0.0-alpha3.
它应该以同样的方式工作com.google.android.material:material:1.0.0-alpha3。
| 归档时间: |
|
| 查看次数: |
9843 次 |
| 最近记录: |