【发布时间】:2017-04-26 06:49:46
【问题描述】:
我已经从 Android Studio 模板中创建了一个带有 Scrolling Activity 的应用程序来测试我的主应用程序的编码是否会影响该行为,所以我只是添加到代码中:
<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
这显示了导航栏后面的 Snackbar 作为此屏幕截图(PS:我正在使用 Xstane 重新设计我的手机上的导航栏,但我认为这不会影响代码因为我尝试使用没有 CollapsingToolbarLayout 的 Snackbar 的 TranslucentNavigation 并且有效好吧)
应用支持
- windowTranslucentNavigation
- 小吃店
- CollapsingToolbarLayout
- 浮动操作按钮
这是主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"
xmlns:tools="http://schemas.android.com/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"
/>
更新:这里是显示 Snackbar 的 FloatingButton 的 onClick 代码(此代码在主活动的 onCreate 中)
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();
}
});
【问题讨论】:
-
请显示代码你是如何显示小吃店的。
-
@VipulAsri 更新
标签: android floating-action-button android-collapsingtoolbarlayout android-snackbar