android顶部(toolbar)搜索框实现代码
2018-01-12 09:27
591 查看
APP中经常会使用到搜索功能,那我们的搜索框该如何布局呢?下面咱们就看一下下面这个效果:
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)搜索框实现的实例详解
- android顶部(toolbar)搜索框实现
- Android 代码实现viewPager+fragment 模仿今日头条的顶部导航
- [置顶] 【Android】Scrollview返回顶部,快速返回顶部的功能实现,详解代码。
- [置顶] 【Android】Listview返回顶部,快速返回顶部的功能实现,详解代码。
- Android仿今日头条和知乎等App顶部滑动导航实现代码分析及源码下载
- Android商城开发系列(五)—— 商城首页回到顶部和搜索框布局实现
- Android顶部工具栏和底部工具栏的简单实现代码
- Android点击按钮返回顶部实现代码
- Android实现双击TitleBar回顶部的功能示例代码
- 【Android】Listview返回顶部,快速返回顶部的功能实现,详解代码。
- 【Android】Scrollview返回顶部,快速返回顶部的功能实现,详解代码。
- Android下利用ToolBar+SearchView实现仿微信搜索框效果
- Android实现listview滑动时渐隐渐现顶部栏实例代码
- Android 代码实现APK install & uninstall
- Android用代码实现EditText不可编辑
- Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法。
- android--Wifi(在真机上操作,未实现,先记录代码)
- 用python脚本实现的android代码管理工具rrdt