gpt4 book ai didi

android - 带有 CoordinatorLayout 的 Snackbar 禁用关闭

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:07:49 27 4
gpt4 key购买 nike

我正在使用支持

  • float 操作按钮
  • snackbar
  • 协调器布局

我需要 CoordinatorLayout 以便在显示 SnackBarFloatingActionButton 向上移动以为 Snackbar 腾出空间。为了更好地理解,请查看此 video .

我正在使用 SnackBar 双回退出应用程序,但 SnackBar 可以被关闭。

有没有办法禁用 SnackBar 上的关闭?

Snackbar snackbar = Snackbar.make(view, R.string.press_back_again_to_exit, Snackbar.LENGTH_SHORT);
snackbar.setAction(R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v)
{

}
});
snackbar.setActionTextColor(getResources().getColor(R.color.white));

View view = snackbar.getView();
view.setBackgroundColor(getResources().getColor(R.color.orange_warning));

snackbar.show();

布局

<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.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true">

<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoFadeColor="@android:color/transparent"
sothree:umanoPanelHeight="100dp"
sothree:umanoShadowHeight="4dp">

<!-- Toolbar and main content -->
<LinearLayout
android:id="@+id/toolbar_and_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

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

<!-- Your content layout -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>

</LinearLayout>

<!-- Sliding up panel layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/darker_grey"
android:orientation="vertical">

...

</LinearLayout>

</com.sothree.slidinguppanel.SlidingUpPanelLayout>


<!-- Navigation drawer -->
<ExpandableListView
android:id="@+id/lv_left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:childDivider="@android:color/transparent"
android:clickable="true"
android:divider="@color/divider_color"
android:dividerHeight="0.6dp"
android:fadeScrollbars="true"
android:groupIndicator="@null"
android:listSelector="@drawable/button_drawer_child_selector"
android:scrollbarSize="0dp"/>

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

<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_marginBottom="@dimen/floating_action_button_margin"
android:layout_marginRight="@dimen/floating_action_button_margin"
android:src="@drawable/ic_add"
android:visibility="invisible"
app:backgroundTint="@color/orange"
app:borderWidth="0dp"
app:elevation="6dp"
app:fabSize="normal"/>

</android.support.design.widget.CoordinatorLayout>

附言

我知道 this GitHub library ,具有此功能,但是否有“本地”方式来实现?

最佳答案

Snackbar 现在实际支持使用 setBehavior 方法禁用滑动关闭。这里最棒的是,以前你总是会失去一些现在保留下来的行为。您还需要使用 Snackbar.LENGTH_INDEFINITE

请注意,包已移动,因此您必须导入"new"Snackbar in the snackbar package .

Snackbar.make(view, stringId, Snackbar.LENGTH_INDEFINITE)
.setBehavior(new NoSwipeBehavior())
.show();

class NoSwipeBehavior extends BaseTransientBottomBar.Behavior {

@Override
public boolean canSwipeDismissView(View child) {
return false;
}
}

关于android - 带有 CoordinatorLayout 的 Snackbar 禁用关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32183509/

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