全屏显示时,BottomNavigationView跳起来留下空白 [英] BottomNavigationView jumps up leaving blank space when fullscreen

查看:168
本文介绍了全屏显示时,BottomNavigationView跳起来留下空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于BottomNavigationView的最后一个标签,我希望内容位于状态栏下方,并使状态栏完全透明。这可以按预期工作,但是当选择了最后一个选项卡时,BottomNavigationView会跳起来,在底部留下一个空格。



SO中有类似的话题,据说将fitWindowSystems设置为false。我尝试过,但没有帮助。感谢您的帮助。





ExplorerFragment.java

 公共类ExplorerFragment扩展Fragment {

public ExplorerFragment(){
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if(Build.VERSION.SDK_INT> = Build.VERSION_CODES.M){
窗口window = getActivity()。getWindow();
window.getDecorView()。setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_IVE
window.setStatusBarColor(ContextCompat.getColor(getContext(),android.R.color.transparent));
}
}

@Override
public void onDestroy(){
super.onDestroy();
if(Build.VERSION.SDK_INT> = Build.VERSION_CODES.M){
View decor = getActivity()。getWindow()。getDecorView();
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}

@Override
public View onCreateView(@NonNull LayoutInflater inflater,ViewGroup container,
Bundle savedInstanceState){

return inflater.inflate(R.layout.fragment_explorer,container,false);
}

}

fragment_explorer.xml

 < android.support.constraint.ConstraintLayout 
xmlns:android = http://schemas.android.com/apk/ res / android
xmlns:tools = http://schemas.android.com/tools
android:layout_width = match_parent
android:layout_height = match_parent xmlns:app = http://schemas.android.com/apk/res-auto
tools:context = com.orevon.fflok.fragments.ExplorerFragment
android:fitsSystemWindows = false>

<查看android:layout_width = 0dp android:layout_height = 180dp
app:layout_constraintTop_toTopOf = parent
app:layout_constraintStart_toStartOf = parent
app:layout_constraintEnd_toEndOf = parent
android:background = @ drawable / splash_background4 />

< /android.support.constraint.ConstraintLayout>

activity_mail.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
android:id = @ + id / main_content
android:layout_width = match_parent
android:layout_height = match_parent
android:fitsSystemWindows = false>

< FrameLayout
android:id = @ + id / fragment_frame
android:layout_width = match_parent
android:layout_height = match_parent
app:layout_behavior = @ string / appbar_scrolling_view_behavior>

< / FrameLayout>

< android.support.design.widget.BottomNavigationView
android:id = @ + id / mainBottomNavigation
android:layout_width = match_parent
android :layout_height = 68dp
app:layout_constraintStart_toStartOf = parent app:layout_constraintEnd_toEndOf = parent
app:layout_constraintBottom_toBottomOf = parent
android:background = @ drawable / bottombar_bg
app:itemIconTint = @ color / bottom_nav_color
app:itemTextColor = @ color / bottom_nav_color
app:menu = @ menu / main_bottom_navigation />

< /android.support.constraint.ConstraintLayout>


解决方案

对于那些遇到问题的人可能有用未来。
我只是通过添加

  ViewCompat.requestApplyInsets(view)
来解决此问题pre>

到我片段的 onActivityCreated 方法中。
视图-片段的根视图


在我看来,是这样的:


科特琳

 替代乐趣onActivityCreated(savedInstanceState:Bundle?){
super.onActivityCreated(savedInstanceState)
视图?.let {
ViewCompat.requestApplyInsets(it)
}
}

JAVA

  @Override 
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
View view = getView()
if(view!= null){
ViewCompat.requestApplyInsets(view)
}
}

更新(6/27/2020):
onActivityCreated 方法已在SDK> = 29上弃用,您可以在 onViewCreated 方法内使用上面的代码:

  override fun onViewCreated(view:View,savedInstanceState:Bundle?){
super.onViewCreated(view,savedInstanceState)
ViewCompat.requestApplyInsets(view)
}


For a BottomNavigationView's last tab, I want the content to be below status bar and make the status bar completely transparent. This works as expected but the BottomNavigationView jumps up leaving a blank space in the bottom when the last tab is selected.

There were similar topics in SO that said to set fitWindowSystems to false. I tried it, but not helping. Any help is appreciated.

ExplorerFragment.java

public class ExplorerFragment extends Fragment {

    public ExplorerFragment() {
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Window window = getActivity().getWindow();
            window.getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                            View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE);
            window.setStatusBarColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            View decor = getActivity().getWindow().getDecorView();
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_explorer, container, false);
    }

}

fragment_explorer.xml

<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context="com.orevon.fflok.fragments.ExplorerFragment"
        android:fitsSystemWindows="false">

    <View android:layout_width="0dp" android:layout_height="180dp"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          android:background="@drawable/splash_background4"/>

</android.support.constraint.ConstraintLayout>

activity_mail.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"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="false">

    <FrameLayout
            android:id="@+id/fragment_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </FrameLayout>

    <android.support.design.widget.BottomNavigationView
            android:id="@+id/mainBottomNavigation"
            android:layout_width="match_parent"
            android:layout_height="68dp"
            app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:background="@drawable/bottombar_bg"
            app:itemIconTint="@color/bottom_nav_color"
            app:itemTextColor="@color/bottom_nav_color"
            app:menu="@menu/main_bottom_navigation"/>

</android.support.constraint.ConstraintLayout>

解决方案

It may be useful for those who face a problem in the future. I solved this issue just by adding

ViewCompat.requestApplyInsets(view)

to my fragment's onActivityCreated method. view - fragment's root view

in my case it looks like:

KOTLIN

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        view?.let {
            ViewCompat.requestApplyInsets(it)
        }
    } 

JAVA

 @Override
    public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            View view = getView()
            if(view != null){
                ViewCompat.requestApplyInsets(view)
            }
        }

Update (6/27/2020): Since onActivityCreated method is deprecated on SDK >=29 you could use the code above inside onViewCreated method:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    ViewCompat.requestApplyInsets(view)
}

这篇关于全屏显示时,BottomNavigationView跳起来留下空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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