我Bottomnavigationview在我的应用程序中使用for标签栏,为此,我正在使用以下代码。请检查一下。
布局:-
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemTextColor="@android:color/black"
app:menu="@menu/bottom_navigation_main" />
Run Code Online (Sandbox Code Playgroud)
我从中得到以下结果,请检查它的图像。
但是问题是,我需要的自定义项目Bottomnavigationview,如下面的图像中所示,该项目的首页上有红色 TextView计数Bottomnavigationview,请检查以下图像。
我已经搜索了它,并获得了它的第三方库,它能够创建我想要的视图。请检查它的库。单击此处。不能不使用任何第三方库而仅Bottomnavigationview使用它吗?
我在此处搜索过SO,但未获得预期结果,请检查我访问过的以下链接。
1.第一链接
2.第二链接
3.第三链接
4.第四链接
5.第五链接
请帮助我解决这个问题。谢谢 :)
我为我的应用程序使用底部导航视图,并希望删除图标下的文本.我在互联网上寻找它但仍然无法找到解决方案.有没有人用来处理这个请给我你的解决方案.
我想要的就像这样:
我的代码在这里:主要布局包含recyclerview和bottomnavigationview:
<LinearLayout
android:weightSum="10"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_marginTop="20dp"
android:layout_weight="8.5"
android:id="@+id/recyclerview_menu"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.BottomNavigationView
android:background="@color/whiteColor"
android:id="@+id/bottom_navigation_bar"
android:layout_weight="1.5"
app:menu="@menu/menu_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.design.widget.BottomNavigationView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是bottomnavigation菜单:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_favorites"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title="Home"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_schedules"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title="Search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_music"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title="Save"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_me"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title="Me"
app:showAsAction="ifRoom" />
Run Code Online (Sandbox Code Playgroud)
在MainActivity中:
mBottomBar = (BottomNavigationView)
findViewById(R.id.bottom_navigation_bar);
disableShiftMode(mBottomBar);
public void disableShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftingMode.setAccessible(true);
shiftingMode.setBoolean(menuView, …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用了BottomNavigationView,当我按下一个项目并加载例如My Ticket片段时,生成QR码需要一段时间,在选择该项目之前会有很大的延迟.我试图将AsyncTask加载到片段中的onResume()和onActivityCreated()中的所有数据,但它不能正常工作.
如何顺利使用底部导航视图和碎片?
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_view);
Menu test = bottomNavigationView.getMenu();
test.add(Menu.NONE, 1, Menu.NONE, "Home").setIcon(R.drawable.ic_action_home);
test.add(Menu.NONE, 2, Menu.NONE, "Agenda").setIcon(R.drawable.ic_action_event);
test.add(Menu.NONE, 3, Menu.NONE, "Ticket").setIcon(R.drawable.ic_action_credit_card);
test.add(Menu.NONE, 4, Menu.NONE, "Profile").setIcon(R.drawable.ic_action_person);
test.add(Menu.NONE, 5, Menu.NONE, "More").setIcon(R.drawable.ic_action_more);
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()) {
case 1:
if(menuFrame.getVisibility() == View.VISIBLE) {
closeBottomMenu();
}
selectedFragment = HomeFragment.newInstance();
break;
case 2:
if(menuFrame.getVisibility() == View.VISIBLE) {
closeBottomMenu();
}
selectedFragment = AgendaFragment.newInstance();
break;
case 3:
if(menuFrame.getVisibility() == View.VISIBLE) { …Run Code Online (Sandbox Code Playgroud) 我试图在底部导航视图上方显示片段主机。但底部导航视图占用了片段主机的一部分。我尝试了其他 SO 答案的解决方案,但仍然没有解决问题。我使用带有“layout_above”属性的相对布局和带有realted属性的约束布局来将片段保持在底部导航视图之上。但片段显示文本视图仍然被底部导航视图截断。
这是我尝试过的 xml 代码:使用相对布局:
<?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: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="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottom_nav_menu" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/nav_host_fragment"
android:layout_alignParentStart="true"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
具有恒定的布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
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>
Run Code Online (Sandbox Code Playgroud)
如何使用 xml 设置底部导航视图上方的片段主机?
我有一个Activity应用程序。我创建了一个Navigation graph包含所有可能目的地的单个(Fragment )。
唯一Activity layout包含一个<fragment/>容器,因为它应该是。
有一个主要片段包含BottomNavigationView用户可以导航到所有重要目的地(其中 3 个)的位置。
当我按照BottomNavigationView官方文档中的许多教程或事件中所述实现 时,它会替换Activity. 因此,BottomNavigationView不再显示 ,因为它包含在 a 中Fragment而不是 中Activity。我想让它向右膨胀layout我希望它能够使主片段中的
我应该使用另一个Navigation graph特定于主片段的吗?我应该使用经典Listener(但我会失去使用经典的所有兴趣Navigation graph)?有我不知道的解决方案吗?
我该如何实施?我尝试创建两个不同的Navigation graph,但无法将其设置为我的BottomNavigationView
android bottomnavigationview android-architecture-navigation android-navigation-graph
如何设置材质组件margin的徽章?bottomNavigation
或者
padding当我们单击某个项目时,我们如何防止出现bottomNavigationView这样的情况,因为正如我们在这些图片中看到的那样,一些徽章会被隐藏。
当第 1 项为unSelected:
当第1项时isSelected(会隐藏一点徽章高度):
android android-layout kotlin bottomnavigationview material-components-android
我通过选择 \xe2\x80\x9cBottom Navigation Activity\xe2\x80\x9d 创建了新的 Android 项目。没有其他改变。仅修改\n\xe2\x80\x9cfragment_notifications.xml\xe2\x80\x9d 通过添加背景属性将背景设置为黑色。
\n
我的问题是:
\n感谢您提前抽出时间。
\n我正在使用 Android Studio 4.1.1 并在 AVD Nexus 6 API 26 上运行代码,下面是相关文件的源代码。除通知片段的背景外,全部由 Android Studio 生成。
\n活动_main.xml:
\n<?xml version="1.0" encoding="utf-8"?>\n<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"\n xmlns:app="http://schemas.android.com/apk/res-auto"\n android:id="@+id/container"\n android:layout_width="match_parent"\n android:layout_height="match_parent"\n android:paddingTop="?attr/actionBarSize">\n\n<com.google.android.material.bottomnavigation.BottomNavigationView\n android:id="@+id/nav_view"\n android:layout_width="0dp"\n android:layout_height="wrap_content"\n android:layout_marginStart="0dp"\n android:layout_marginEnd="0dp"\n android:background="?android:attr/windowBackground"\n app:layout_constraintBottom_toBottomOf="parent"\n app:layout_constraintLeft_toLeftOf="parent"\n app:layout_constraintRight_toRightOf="parent"\n app:menu="@menu/bottom_nav_menu" />\n\n<fragment\n android:id="@+id/nav_host_fragment"\n android:name="androidx.navigation.fragment.NavHostFragment"\n android:layout_width="match_parent"\n android:layout_height="match_parent"\n app:defaultNavHost="true"\n app:layout_constraintBottom_toTopOf="@id/nav_view"\n app:layout_constraintLeft_toLeftOf="parent"\n app:layout_constraintRight_toRightOf="parent"\n app:layout_constraintTop_toTopOf="parent"\n app:navGraph="@navigation/mobile_navigation" />\n\n</androidx.constraintlayout.widget.ConstraintLayout>\nRun Code Online (Sandbox Code Playgroud)\nmobile_navigation.xml如下:
\n<?xml version="1.0" encoding="utf-8"?>\n<navigation xmlns:android="http://schemas.android.com/apk/res/android"\n xmlns:app="http://schemas.android.com/apk/res-auto"\n xmlns:tools="http://schemas.android.com/tools"\n android:id="@+id/mobile_navigation"\n …Run Code Online (Sandbox Code Playgroud) 升级依赖后:
'com.google.android.material:material:xxx'
从1.4.0到1.5.0,导航项文本以某种方式从锚定在图标下方更改为图标上方:
从:
到:
这是一个功能还是一个错误,有修复吗?
我有一个非常简单的应用程序,由三个片段和一个底部导航栏组成,是通过使用 Android Studio 中的“新项目 -> 底部导航活动”创建的。第一个片段包含一个按钮,它应该将我带到第二个片段,就像单击底部导航栏的中间按钮一样。

有没有一个“标准”的方法来做到这一点?
我努力了:
launch(...)导航组件,该组件似乎使用自己的后堆栈启动片段并破坏底部导航。setSelectedItemId(...),这要么导致异常,要么以不同的方式破坏底部导航。android bottomnavigationview android-bottomnav android-architecture-navigation