【发布时间】:2015-11-17 22:45:04
【问题描述】:
我正在使用支持
- 浮动操作按钮
- 小吃店
- 协调器布局
我需要 CoordinatorLayout 以便在显示 SnackBar 时 FloatingActionButton 向上移动以为 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 进行双退以退出应用程序 - 你违背了平台的 UI 模式。 SnackBars 用于小反馈,而不是要求用户采取行动(就像我假设您在用户按下两次时尝试做的那样)
-
@Luksprog 我知道,同样可以用 Toast 或 Crouton 来实现,但基本相同,SnackBar 看起来更好。我个人不喜欢双退退出,但不幸的是,这不是我能决定的。
-
检查我的答案.....stackoverflow.com/a/35576829/1881527
标签: android android-coordinatorlayout android-snackbar