gpt4 book ai didi

android - NavBar 下方的 BottomNavigationBar

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:26 26 4
gpt4 key购买 nike

目标:

1) 使状态栏透明 - 完成

2) 使BottomNavigationViewNavbar 颜色相同。 - 几乎完成

问题

通过在我的 Activity 中添加以下代码,状态栏变得透明。但是,BottomNavigationView 位于 NavBar 下方。如果删除这行代码,StatusBar 将不再透明。你感觉到我在这里的痛苦吗?此外...如何使布局的 TOP 位于状态栏下方?

Activity 中的代码:

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);
}

Activity 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>

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>

enter image description here

最佳答案

BottomNavigationBar underneath NavBar

你的的原因BottomNavigationView 躲在后面NavBar 因为你正在设置这个标志

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

使用该标志查看结果

enter image description here

简单的解决方案

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

并使用下面的标志

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

Root layout

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

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

<?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

<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>

Finally OUTPUT

enter image description here

Finally OUTPUT on kitkat

enter image description here

关于android - NavBar 下方的 BottomNavigationBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52294746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com