带有半透明导航的Snackbar和CollapsingToolbarLayout

编程入门 行业动态 更新时间:2024-10-27 22:31:30
本文介绍了带有半透明导航的Snackbar和CollapsingToolbarLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经从Android Studio Templets创建了一个具有滚动活动功能的应用程序,以测试我对主应用程序的编码是否影响该行为,所以我只添加了代码:

I have Created an app with Scrolling Activity from the Android Studio Templets to test my coding of my main App affects that behavior or not, so I have just add to the code :

<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>

该快照屏幕截图显示了导航栏后面的Snackbar(PS:我正在使用Xstane重新设计手机上的导航栏,但我认为这不会影响代码,因为我尝试了不带CollapsingToolbarLayout的Snackbar的TranslucentNavigation,并且可以正常工作很好)

that shows the Snackbar behind the navigation bar as this screenshot (PS : I am using Xstane for redesigning my Navigation bar on my mobile but I think that does not affect the code cuz i have tried TranslucentNavigation with Snackbar Without CollapsingToolbarLayout and that works well)

该应用程序正在支持

  • windowTranslucentNavigation
  • 小吃吧
  • CollapsingToolbarLayout
  • FloatingActionButton

这是主要xml的代码

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="schemas.android/apk/res/android" xmlns:app="schemas.android/apk/res-auto" xmlns:tools="schemas.android/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context=".testscanbarwithcollapsing.ScrollingActivity" > <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="@dimen/app_bar_height" android:fitsSystemWindows="true" android:theme="@style/AppTheme.AppBarOverlay" > <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed" > <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_scrolling"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" app:layout_anchor="@id/app_bar" app:layout_anchorGravity="bottom|end" app:srcCompat="@android:drawable/ic_dialog_email" />

UPDATED:这是显示Snackbar的FloatingButton的onClick的代码(此代码位于主要活动的onCreate中)

UPDATED : here is the code of the onClick of the FloatingButton that show the Snackbar (this code is in onCreate of the main activity)

fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { fabProgressCircle.show(); Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } });

推荐答案

private static void show(final Activity activity, Snackbar snackbar) { if (ScreenUtils.isTranslucentNavigationBar(activity)){ final FrameLayout snackBarView = (FrameLayout) snackbar.getView(); final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) snackBarView.getChildAt(0).getLayoutParams(); params.setMargins(params.leftMargin, params.topMargin, params.rightMargin, params.bottomMargin + ScreenUtils.getNavigationBarHeight(activity)); snackBarView.getChildAt(0).setLayoutParams(params); } snackbar.show(); } public static boolean isTranslucentNavigationBar(Activity activity) { Window w = activity.getWindow(); WindowManager.LayoutParams lp = w.getAttributes(); int flags = lp.flags; return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; }

这个理想对我有用!

更多推荐

带有半透明导航的Snackbar和CollapsingToolbarLayout

本文发布于:2023-11-04 05:55:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557130.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Snackbar   CollapsingToolbarLayout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!