导航栏下方的BottomNavigationBar [英] BottomNavigationBar underneath NavBar

查看:83
本文介绍了导航栏下方的BottomNavigationBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:

1)使状态栏透明-完成

1) Make the status bar transparent - Done

2)使BottomNavigationViewNavbar具有相同的颜色. -几乎完成

2) Make the BottomNavigationView and the Navbar the same color. - Almost Done

问题

通过在我的Activity中添加以下代码,状态栏将变为透明.但是,BottomNavigationView落在NavBar之下.如果删除此行代码,则StatusBar不再透明.你在这里感到我的痛苦吗?此外...我该如何将布局的 TOP 放在状态栏的下面?

By adding the following code in my Activity, the status bar becomes transparent. BUT, BottomNavigationView falls underneath the NavBar. If I remove this line of code, the StatusBar no longer is transparent. You feel my pain here? Furthermore... How would I make the TOP of the layout go underneath the statusbar?

活动中的代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    Window w = getWindow();
    w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, 
    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

活动XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="false">

<com.custom.app.view.ClickableViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/tab_layout" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/custom_black"
    app:itemIconTint="@color/white"
    app:itemTextColor="@color/white"
    app:menu="@menu/bottom_navigation_main" />

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

The Style.xml

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/md_white_1000</item>
    <item name="android:actionMenuTextColor">@color/custom_black</item>
    <item name="actionMenuTextColor">@color/custom_black</item>
    <item name="android:alertDialogStyle">@style/AppTheme.AlertDialog</item>
    <item name="colorControlNormal">@color/md_white_1000</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:navigationBarColor">@color/custom_black</item>
</style>

推荐答案

NavBar下方的BottomNavigationBar

BottomNavigationBar underneath NavBar

您的 BottomNavigationView 躲在 NavBar 后面的原因,因为您正在设置此标志

The reason your BottomNavigationView hiding behind NavBar because your are setting this flags

w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, 
    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

使用该标志查看结果

简单的解决方案

要使您的statusbar透明,只需使用 <item name="colorPrimaryDark">@android:color/transparent</item>

To make your statusbar transparent just use <item name="colorPrimaryDark">@android:color/transparent</item>

并使用以下标志

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

根目录

您需要使用 android.support.design.widget.CoordinatorLayout 作为rootlayout

CartActivity

CartActivity

public class CartActivity extends AppCompatActivity {

    BottomNavigationView bottomNavigationView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {

            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        setContentView(R.layout.activity_cart);

        bottomNavigationView = findViewById(R.id.tab_layout);


    }

}

layout.activity_cart

layout.activity_cart

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#199bd2"
    android:fitsSystemWindows="true">


    <android.support.design.widget.BottomNavigationView
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="#000"
        app:itemIconTint="#FFFFFF"
        app:itemTextColor="#FFFFFF"
        app:menu="@menu/bottom_navigation_main" />


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

CustAppTheme2

CustAppTheme2

<style name="CustAppTheme2" parent="Theme.AppCompat.DayNight.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@android:color/transparent</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlNormal">#FFFFFF</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:navigationBarColor">#000</item>

</style>

最终输出

kitkat的最终产量

Finally OUTPUT on kitkat

这篇关于导航栏下方的BottomNavigationBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆