android如何实现顶部toolbar搜索框-创新互联

这篇文章主要为大家展示了“android如何实现顶部toolbar搜索框”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“android如何实现顶部toolbar搜索框”这篇文章吧。

我们提供的服务有:成都网站建设、网站制作、微信公众号开发、网站优化、网站认证、含山ssl等。为超过千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的含山网站制作公司

效果:

android如何实现顶部toolbar搜索框

xml布局:

<?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"
                         android:id="@+id/main_content"
                         android:layout_width="match_parent"
                         android:layout_height="match_parent"
                         android:focusableInTouchMode="true"
                         android:fitsSystemWindows="true">

  <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="16dp"
      android:text="@string/large_text" />
  </android.support.v4.widget.NestedScrollView>

  <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="@color/colorPrimary"
      app:layout_scrollFlags="scroll|enterAlways"
      app:title="标题栏"
      app:navigationIcon="@mipmap/navigation_back_white"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <RelativeLayout
      android:id="@+id/search_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/toolbar"
      android:background="@color/colorPrimary"
      android:padding="16dp">

      <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableLeft="@android:drawable/ic_menu_camera"
        android:drawablePadding="22dp"
        android:drawableRight="@android:drawable/ic_menu_search"
        android:gravity="left|center"
        android:hint="请输入搜索内容"
        android:padding="10dp"
        android:textColorHint="@android:color/darker_gray" />
    </RelativeLayout>

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

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

Activity直接引用布局即可:

public class StopSearchViewBelowToolbarActivity extends AppCompatActivity {

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stop_search_view_toolbar_layout);
  }
}

这里就是充分使用了CoordinatorLayout、AppBarLayout、NestedScrollView、Toolbar的特性来完成的效果,并没有添加其他什么逻辑。

以上是“android如何实现顶部toolbar搜索框”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!

当前题目:android如何实现顶部toolbar搜索框-创新互联
转载源于:https://www.cdcxhl.com/article24/dichje.html

成都网站建设公司_创新互联,为您提供网站收录外贸网站建设网站设计网站营销面包屑导航企业建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化