gpt4 book ai didi

android - Snackbar 顶部的 float 操作按钮。如何?

转载 作者:行者123 更新时间:2023-11-29 17:33:30 28 4
gpt4 key购买 nike

我试图在 SnackBar 顶部显示我的 FloatingActionButton,但我无法像在其他屏幕上那样显示它。我当前的布局是这样的:

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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="true">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="@dimen/toolbar_elevation"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.ToolbarPopUp"
app:theme="@style/AppTheme.Toolbar"/>

<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
style="@style/Feed.TabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"/>

<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_fab"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@drawable/ic_start"
app:backgroundTint="@color/h19_green"
app:elevation="6dp"
app:pressedTranslationZ="12dp"/>
</android.support.design.widget.CoordinatorLayout>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/navdrawer"/>

</android.support.v4.widget.DrawerLayout>

我的 Snackbar 代码是这个:

@Override
public void alertNoInternetConnection() {
CoordinatorLayout coordinatorLayout = ButterKnife.findById(getActivity(), R.id.coordinator_fab);
Snackbar.make(coordinatorLayout, R.string.connection_offline, Snackbar.LENGTH_INDEFINITE).show();
}

我应该如何重新组织布局,以便在显示 Snackbar 时, float 操作按钮悬停在其上方?

最佳答案

我一直在寻找答案,最后我找到了适合我的解决方案:

  1. FloatingActionButton 必须在内部 CoordinatorLayout
  2. Snackbar 应该接收 FloatingActionButton 作为 View 参数

布局:

 <android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.FloatingActionButton
android:id="@+id/fabAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@mipmap/ic_create_white_48dp"
/>
</android.support.design.widget.CoordinatorLayout>

代码:

FloatingActionButton fabAdd = (FloatingActionButton)findViewById(R.id.fabAdd);
Snackbar.make(fabAdd, "Record was removed.", Snackbar.LENGTH_SHORT).show();

关于android - Snackbar 顶部的 float 操作按钮。如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31744435/

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