国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android頂部(toolbar)搜索框實現代碼

2019-12-12 01:18:36
字體:
來源:轉載
供稿:網友

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的特性來完成的效果,并沒有添加其他什么邏輯。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沙雅县| 丰台区| 子长县| 北流市| 江安县| 岐山县| 牡丹江市| 镇康县| 徐州市| 宝清县| 灵丘县| 乐清市| 大埔区| 顺义区| 浙江省| 奎屯市| 怀柔区| 盖州市| 泉州市| 阿城市| 卢湾区| 安溪县| 炉霍县| 高碑店市| 隆子县| 红桥区| 靖安县| 万山特区| 剑阁县| 高陵县| 乌海市| 儋州市| 永和县| 龙岩市| 中阳县| 安龙县| 巴青县| 聂拉木县| 武功县| 西华县| 西畴县|