【问题标题】:Fab to search barFab 到搜索栏
【发布时间】:2015-09-23 23:20:12
【问题描述】:

我希望为我的 android 应用程序制作一个浮动操作按钮,点击后会变成搜索栏。

我看到他们变成了actionbartoolbar,但我想用它来搜索。如有任何帮助,我们将不胜感激。

谢谢!

【问题讨论】:

标签: android


【解决方案1】:

您可以通过 3 个步骤完成此操作。

  1. 浮动操作按钮,你可以使用谷歌支持库,我已经解释了here

  2. 单击浮动操作按钮时,您需要显示工具栏, 为此,您的主页应该有 FAB 和工具栏,如下所示:

    <LinearLayout android:id="@+id/mainView"
                  xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="0dp"
                  android:layout_height="fill_parent"
                  android:layout_weight="1.0"
                  android:orientation="vertical">
    
        <include
            android:id="@+id/toolbar"
            layout="@layout/app_bar"/>
    
        <View android:id="@+id/stripBelowToolbar"
              android:layout_height="0dp"
              android:layout_width="fill_parent"/>
    
        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/rootLayout"
            android:layout_height="match_parent"
            android:layout_width="match_parent">
    
        <android.support.design.widget.FloatingActionButton
            style="@style/fab_style"
            android:id="@+id/fabBtn"
            android:layout_gravity="bottom|right"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            fab:backgroundTint="@color/sap_uex_dark_yellow"
            fab:rippleColor="@color/white"/>
    

    文件后面的代码应该有

    FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            toolbar.setvisibility(View.VISIBLE)// show the searchbox and bla bla...
        }
    });
    
  3. 需要动画悬浮动作按钮的隐藏,可以像this那样实现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多