看到新的指南出来了,并在google photos最新的应用程序中使用.不知道如何使用新的底部导航栏.通过新的支持lib查看,没有发现任何领先优势.

找不到任何官方样品.
如何使用新的底栏?不想做任何自定义.
我正在使用android.support.design.widget.BottomNavigationView支持库中的新功能.如何从代码中设置当前选择?我意识到,旋转屏幕后,选择会更改回第一项.当然,它也将有所帮助,如果有人能告诉我,如何"拯救"的当前状态BottomNavigationView的onPause功能,以及如何将其在恢复onResume.
谢谢!
我正在使用设计支持库版本25中的android.support.design.widget.BottomNavigationView
compile 'com.android.support:design:25.0.0'
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
app:itemBackground="@color/colorPrimary"
app:menu="@menu/bottom_navigation_main"
android:forceHasOverlappingRendering="true"/>
Run Code Online (Sandbox Code Playgroud)
当@ menu/bottom_navigation_main中只有三个动作时,它会一直显示图标和文本标签.
当有三个以上的操作时,始终显示图标和文本标签的方法是什么.
android android-support-library android-support-design bottomnavigationview
我已经实现了我的应用程序底部的导航视图和我看过的每一个地方上的,如图标上方显示的徽章这个 我不知道这是否是甚至有可能实现.任何帮助表示赞赏.谢谢.
我正在尝试使用新的导航组件.我使用带有navController的BottomNavigationView:NavigationUI.setupWithNavController(bottomNavigation,navController)
但是当我切换片段时,即使它们以前被使用过,它们也会每次都被破坏/创建.
有没有办法让我们的主要片段链接到我们的BottomNavigationView?
Android Jetpack导航,BottomNavigationView在后退按钮上点击自动片段后栈?
我想要的是,在用户一个接一个地选择多个标签后,用户点击后退按钮应用必须重定向到他/她打开的最后一页.
通过在ArrayList中保存当前选定的项目,我使用Android ViewPager实现了相同的功能.Android Jetpack导航发布后是否有任何自动后退堆栈?我想用导航图实现它
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".main.MainActivity">
<fragment
android:id="@+id/my_nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
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/navigation" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
navigation.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"
android:title="@string/title_home" />
<item
android:id="@+id/navigation_people"
android:icon="@drawable/ic_group"
android:title="@string/title_people" />
<item
android:id="@+id/navigation_organization"
android:icon="@drawable/ic_organization"
android:title="@string/title_organization" />
<item
android:id="@+id/navigation_business"
android:icon="@drawable/ic_business"
android:title="@string/title_business" />
<item
android:id="@+id/navigation_tasks"
android:icon="@drawable/ic_dashboard"
android:title="@string/title_tasks" />
</menu>
Run Code Online (Sandbox Code Playgroud)
还补充道
bottomNavigation.setupWithNavController(Navigation.findNavController(this, R.id.my_nav_host_fragment))
Run Code Online (Sandbox Code Playgroud)
我得到了一个答案Levi …
android android-navigation bottomnavigationview android-architecture-components android-architecture-navigation
以下是我选择的底部导航视图项的代码
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment = null;
switch (item.getItemId()) {
case R.id.action_one:
// Switch to page one
fragment = FragmentA.newInstance();
break;
case R.id.action_two:
// Switch to page two
fragment = FragmentB.newInstance();
break;
case R.id.action_three:
// Switch to page three
fragment = FragmentC.newInstance();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.container,fragment,"TAG").commit();
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
现在我的问题是每次重新创建片段并且不希望每次我都尝试添加addToBackStack(null)时重新创建片段,但是这种情况在后面按钮按下时会不断地从堆栈中弹出片段,这是我不想要的.
有没有办法在选定的底部导航栏上显示片段而无需重新创建片段
android android-fragments android-support-library bottomnavigationview
我必须在向上滚动时隐藏底部导航视图并在向下滚动时显示.如何实现这一点?我的布局是这样的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_above="@+id/navigation"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp">
<FrameLayout
android:id="@+id/container1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:menu="@menu/dashboard_slider_menu" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我附上了视图的截图.请检查一下.
android android-layout android-fragments bottomnavigationview