gpt4 book ai didi

android - 很棒的搜索栏

转载 作者:行者123 更新时间:2023-11-29 01:28:05 26 4
gpt4 key购买 nike

我想为我的 Android 应用制作一个 float 操作按钮,点击后它会变成搜索栏。

我看到它们变成了 actionbar toolbar ,但我想用它来搜索。任何有助于实现这一目标的帮助都将不胜感激。

谢谢!

最佳答案

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

  1. float 操作按钮,您可以使用我已经解释过的 Google 支持库 here .

  2. 单击 float 操作按钮时,您需要显示工具栏,为此,您的主页应该有 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. 您需要为 float 操作按钮的隐藏设置动画,这可以像this 那样实现。 .

关于android - 很棒的搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32751024/

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