标签: bottomnavigationview

当遵循单一活动设计时,如何隐藏底部栏导航?

我试图仅在几个片段中显示底部栏导航(即在大部分片段中隐藏它)。

我阅读了有关此内容的官方文档,但我不清楚,比如我应该将代码放在哪里,并且我在 StackOverFlow 上阅读了对此的评论,例如“我很惊讶文档中建议这样做,因为它实际上看起来非常糟糕因为侦听器在新片段放置在屏幕上之前触发,导致可见的闪烁(有时存在,有时不存在) ”。

我对此进行了研究,根据我的理解,我需要创建一个嵌套的 naviagtion_graph (导航)或其他东西,听 onDestinationChanged 并将底部导航或工具栏设置为 Gone..

我不太明白这一点..我只是想隐藏大多数片段中的底部栏导航..

这是我的 navigation_gragh ( mobile_navigation) :

<navigation 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/mobile_navigation"
    app:startDestination="@+id/navigation_home">

    <fragment
        android:id="@+id/navigation_home"
        android:name="com.example.testingbottomnav.ui.home.HomeFragment"
        android:label="@string/title_home"
        tools:layout="@layout/fragment_home" >
        <action
            android:id="@+id/action_navigation_home_to_newScreenFragment"
            app:destination="@id/newScreenFragment" />
    </fragment>

    <fragment
        android:id="@+id/navigation_dashboard"
        android:name="com.example.testingbottomnav.ui.dashboard.DashboardFragment"
        android:label="@string/title_dashboard"
        tools:layout="@layout/fragment_dashboard" />

    <fragment
        android:id="@+id/navigation_notifications"
        android:name="com.example.testingbottomnav.ui.notifications.NotificationsFragment"
        android:label="@string/title_notifications"
        tools:layout="@layout/fragment_notifications" />
    <fragment
        android:id="@+id/newScreenFragment"
        android:name="com.example.testingbottomnav.ui.newscreen.NewScreenFragment"
        android:label="fragment_new_screen"
        tools:layout="@layout/fragment_new_screen" />
</navigation>
Run Code Online (Sandbox Code Playgroud)

这是我的activity_main.xml

<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:labelVisibilityMode="selected" …
Run Code Online (Sandbox Code Playgroud)

android android-fragments kotlin bottomnavigationview android-bottomnav

5
推荐指数
2
解决办法
4833
查看次数

从片段导航时底部导航栏出现故障

我将底部导航栏与导航组件一起使用

为了使这两个组件协同工作,我调用了:

bottomNavigationView.setupWithNavController(navController)
Run Code Online (Sandbox Code Playgroud)

一切都按预期工作,除非我从片段内部而不是底部导航栏导航

在此输入图像描述

“查看全部”从底部导航栏打开与“报告”相同的片段

binding.viewAllScansTv.setOnClickListener {
    val action = MainFragmentDirections.actionMainFragmentToReportsFragment()
    navController.navigate(action)
}
Run Code Online (Sandbox Code Playgroud)

单击“查看全部”后,片段将打开,“报告”按钮被选中,但是,导航回“主页”不再起作用

我该如何解决这种奇怪的行为?

导航图:

<navigation app:startDestination="@id/mainFragment">
    <fragment
        android:id="@+id/mainFragment"
        android:name="com.package.name.ui.main.MainFragment"
        android:label="MainFragment"> 
        <action                android:id="@+id/action_mainFragment_to_reportsFragment"
            app:destination="@id/reportsFragment" />
    </fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)

底部导航菜单:

<menu>
    <item
        android:id="@+id/mainFragment"
        android:title="Home"/>    
    <item
        android:id="@+id/reportsFragment"
        android:title="Reports"/>
    <item
        android:id="@+id/settingsFragment"
        android:title="My account"/>
</menu>
Run Code Online (Sandbox Code Playgroud)

navigation android bottomnavigationview

5
推荐指数
1
解决办法
3164
查看次数

Flutter - 如何将小吃栏定位在系统导航栏上方

我的应用程序中有一个透明的系统导航栏。

在此输入图像描述

应用程序使用 Getx 小吃栏来抛出错误和成功消息。我所困扰的是,每当应用程序抛出一个小吃店时,小吃店都会通过透明导航栏出现和消失(我可以看到小吃店通过导航栏移动)。有什么办法让小吃栏出现在导航栏上方吗?如何将小吃栏放置在系统导航栏上方?

flutter bottomnavigationview flutter-getx

5
推荐指数
1
解决办法
3774
查看次数

Android BottomNavigationView:图标和文本之间的空间太大

截至最近,底部导航栏开始在文本和图标之间包含一些奇怪的空间(我认为在更新依赖项之后):

在此输入图像描述
(红色是为了看清边界)

现在图标和文本之间似乎有一个间隔符,它将两者推到了栏的最末端。到目前为止,我发现的只是尝试app:itemPaddingTop手动将图标推回原处,但这会破坏较小设备上的视图。

这是 XML:

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="?android:attr/windowBackground"
        app:itemBackground="@color/darkGalaxy"
        app:itemIconTint="@color/bottom_nav_color_selector"
        app:itemTextColor="@color/bottom_nav_color_selector"
        app:labelVisibilityMode="labeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent="0.1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />
Run Code Online (Sandbox Code Playgroud)

有没有办法让它们都以最小的边距垂直居中?

基本上看起来像这样:
在此输入图像描述

android bottomnavigationview android-bottomnav

5
推荐指数
1
解决办法
4938
查看次数

BottomNavigationView getmaxitemcount

你好成员stackoverflow porblem与bottomnavihationview

在我的应用程序中,我使用BottomNavigationView和4项.它使我的应用程序容易和美丽

  BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_view);
        bottomNavigationView.inflateMenu(R.menu.menu_bottom_navigation);
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                int id = item.getItemId();
                switch (id){
                    case R.id.action_one:

                        break;
                    case R.id.action_two:
                        FragmentTransaction manger= getSupportFragmentManager().beginTransaction();
                        pop_web_view  pop3 =new pop_web_view();
                        pop3.show(manger,null);

                        break;
                    case R.id.action_three:

                        break;
                    case R.id.action_four:

                        break;
                }

                return false;
            }
        });
Run Code Online (Sandbox Code Playgroud)

在activity_main中:

<android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchorGravity="bottom"
        android:paddingTop="560dp"
        app:itemBackground="@color/colorDivider"
        app:itemIconTint="@color/colorPrimaryDark"
        app:itemTextColor="@color/colorPrimaryDark"
        app:menu="@menu/menu_bottom_navigation" />
Run Code Online (Sandbox Code Playgroud)

在菜单xml中:

<?xml version="1.0" encoding="utf-8"?>
<menu
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/action_one"
        android:icon="@android:drawable/ic_secure"
        android:title="One"/>
    <item
        android:id="@+id/action_two"
        android:icon="@android:drawable/ic_dialog_info"
        android:title="Two"/>
    <item
        android:id="@+id/action_three"
        android:icon="@android:drawable/ic_dialog_email"
        android:title="Three"/> …
Run Code Online (Sandbox Code Playgroud)

java android bottomnavigationview

4
推荐指数
1
解决办法
5281
查看次数

当键盘出现时,BottomNavigationView会上升

图片

我的BottomNavigationView工作正常,但是当我按下它上面时它会上升EditText.上面的链接上有一个图像.

这是我所包含的清单,android:windowSoftInputMode="adjustPan"但它对我不起作用.还有其他建议吗?

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
Run Code Online (Sandbox Code Playgroud)

我的xml文件:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:design="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.segunfamisa.sample.bottomnav.MainActivity">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/mainToolbar"
        android:background="#ffffff"
        android:titleTextColor="#ffffff">
    </android.support.v7.widget.Toolbar>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@drawable/shadow_top"/>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#ffffff">

    </FrameLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@drawable/shadow"/>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        design:menu="@menu/bottom_nav_items"
        design:itemIconTint="@drawable/selector"
        design:itemTextColor="@drawable/selector"
        android:background="#000000" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android bottomnavigationview

4
推荐指数
1
解决办法
2268
查看次数

使BottomNavigationView停留在其他视图下

我已经实现了BottomNavigationView(BNV)。我的BNV始终停留在其他视图的顶部,如何使其停留在其他视图的顶部?

这是我的看法

<RelativeLayout xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
            android:id="@+id/bottomNavi"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/color_bottom_navi"
            app:itemBackground="@drawable/selector_navi_bottom"
            app:itemIconTint="@color/colorPrimary"
            app:itemTextColor="@color/colorPrimary"
            app:menu="@menu/bottom_navigation" />
        <FrameLayout
            android:id="@+id/frm_content_full"
            android:layout_width="match_parent"
            android:background="@color/colorPrimaryDark"
            android:layout_height="match_parent" />
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这就是它所显示的。

在此处输入图片说明

谢谢。

编辑1: BNV下方的空间用于AdView,我的问题是我使用上述代码时,屏幕将变为蓝色,BNV将被隐藏。

android android-layout bottomnavigationview

4
推荐指数
1
解决办法
4547
查看次数

底部导航和协调器布局中的可滚动工具栏

大家好

我正在尝试正确完成我的布局的scroll_behaviour。我的问题是,如果我将底部导航包装到相对的布局中,然后将主要内容放在其上方,那么当工具栏隐藏时,底部导航会滚动出屏幕。如果将底部导航作为协调器布局的另一个直接子级,则主要内容在我的BottomNavigation之后。我不想在主导航栏的底部添加填充/边距来解决此问题。您有什么提示或想法吗?

另一件事是,我的底部导航的涟漪效应仅在底部导航的顶部可见,而在我的主要内容之上而不可见。

向底部导航添加scroll_behaviour也不起作用。我想尝试固定的底部导航,或者在向下滚动时添加滚动动画,如google材质设计指南中所示。

这里的截图:

应用截图

这是布局代码:

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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"
android:fitsSystemWindows="true"

>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:elevation="0dp"
    >


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways"
        >

    </android.support.v7.widget.Toolbar>


</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >
    <com.getproperly.properlyv2.classes.misc.CustomViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</RelativeLayout>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_anchorGravity="bottom"
    app:layout_anchor="@id/rl"
    app:menu="@menu/bottom_navigation_main"
    />

<com.getproperly.properlyv2.classes.misc.SelfAwareFloatingActionButton
    android:id="@+id/fab_add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_add_white"
    app:fabSize="normal"
    app:layout_anchor="@id/rl"
    app:layout_anchorGravity="bottom|right|end"
    app:layout_behavior="com.getproperly.properlyv2.classes.misc.ScrollAwareFABBehavior"
    android:layout_marginEnd="@dimen/fab_margin"
    android:layout_marginLeft="@dimen/fab_margin"
    android:layout_marginRight="@dimen/fab_margin"
    android:layout_marginStart="@dimen/fab_margin"
    android:layout_marginTop="@dimen/fab_margin"
    android:layout_marginBottom="64dp"/>
Run Code Online (Sandbox Code Playgroud)

感谢任何帮助!谢谢

android scrollable android-toolbar android-coordinatorlayout bottomnavigationview

4
推荐指数
1
解决办法
3748
查看次数

选中时,BottomNavigationView图标不会更改颜色

我试过在我的应用程序中使用BottomNavigationView.

当我单击图标片段时,正确显示片段,但图标在选择时不会更改其颜色,第一个片段的图标保持彩色.它看起来像我选择的任何片段

我做错了什么或者所选片段的图标颜色是单独调整的吗?

我的MainActivity:

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

    private Toolbar toolbar;

    public static FloatingActionButton addDeadline;
    BottomNavigationView bottomNavigationView;
    FrameLayout frameLayout;

    private HomeFragment homeFragment;
    private RecyclerViewFragment recyclerViewFragment;
    private HistoryFragment historyFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_drawer);

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);// language configuration
        String lang = getResources().getConfiguration().locale.getDisplayLanguage(Locale.CHINESE);
        Locale locale = new Locale(lang);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config, null);

        toolbar = findViewById(R.id.toolbar_main);
        setSupportActionBar(toolbar);

        homeFragment = new HomeFragment();
        recyclerViewFragment = new …
Run Code Online (Sandbox Code Playgroud)

icons android colors android-fragments bottomnavigationview

4
推荐指数
1
解决办法
2857
查看次数

Android BottomNavigationView带徽章

不支持在Android中的BottomNavigationView中添加徽章.

如何将带有数字的徽章添加到BottomNavigationView中的特定选项卡.我需要它本地完成没有第三方库.

我正在使用Xamarin原生的MvvmCross.

android mvvmcross xamarin bottomnavigationview

4
推荐指数
1
解决办法
5305
查看次数