Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使小吃店和晶圆厂一起搬迁_Android_Android Coordinatorlayout_Floating Action Button_Android Snackbar - Fatal编程技术网

Android 如何使小吃店和晶圆厂一起搬迁

Android 如何使小吃店和晶圆厂一起搬迁,android,android-coordinatorlayout,floating-action-button,android-snackbar,Android,Android Coordinatorlayout,Floating Action Button,Android Snackbar,我想把快餐店和晶圆厂搬到一起,就像在默认行为中发生一样,但默认情况下,只有当我们点击晶圆厂时,晶圆厂才会发生,晶圆厂为snackbar让位,晶圆厂本身也会向上移动 但是,如果我想让它发生在其他事件发生时,比如版面上的其他按钮,而不是fab本身,那么当版面上的其他按钮单击时,我如何触发fab向上移动并为snackbar腾出位置呢 谢谢 一次点击按钮: public void onClick(View view) { if(spinner.getText().length

我想把快餐店和晶圆厂搬到一起,就像在默认行为中发生一样,但默认情况下,只有当我们点击晶圆厂时,晶圆厂才会发生,晶圆厂为snackbar让位,晶圆厂本身也会向上移动

但是,如果我想让它发生在其他事件发生时,比如版面上的其他按钮,而不是fab本身,那么当版面上的其他按钮单击时,我如何触发fab向上移动并为snackbar腾出位置呢

谢谢

一次点击按钮:

 public void onClick(View view) {
             if(spinner.getText().length() <= 0){
                 showListMenu(spinner);
             }else{
                 showSnack("Added to bag we will hold it for 1 hour!", view.getRootView());
             }
        }

用snackbar锚定fab,如下所示:

Snackbar.make(view.findViewById(R.id.fab), getResources().getString(R.string.fab_msg), Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();

用snackbar锚定fab,如下所示:

Snackbar.make(view.findViewById(R.id.fab), getResources().getString(R.string.fab_msg), Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();
使用CoordinatorLayout就足够了,不需要对Java代码进行任何更改。将您的按钮添加到Coordinator布局中

使用CoordinatorLayout就足够了,不需要对Java代码进行任何更改。将您的按钮添加到Coordinator布局中


发布Java代码请发布Java代码请发布Lackhawk的答案有效。只需删除一个视图。makeviewblackHawk的答案有效。只需在.makeview之后删除一个视图
    <?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"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
  fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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