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

首頁 > 系統(tǒng) > Android > 正文

android頂部(toolbar)搜索框?qū)崿F(xiàn)代碼

2019-10-22 18:17:07
字體:
供稿:網(wǎng)友

APP中經(jīng)常會使用到搜索功能,那我們的搜索框該如何布局呢?下面咱們就看一下下面這個效果:

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="標(biāo)題欄"      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="請輸入搜索內(nèi)容"        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的特性來完成的效果,并沒有添加其他什么邏輯。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 象山县| 灌南县| 利津县| 富源县| 东海县| 鹿泉市| 镇赉县| 新疆| 伽师县| 红河县| 南皮县| 无棣县| 玉环县| 波密县| 高台县| 乌兰察布市| 濮阳县| 来宾市| 桐梓县| 四会市| 海宁市| 彩票| 阿拉善左旗| 旌德县| 深圳市| 广州市| 民乐县| 广安市| 桓台县| 玛曲县| 鸡东县| 沧源| 临沭县| 若羌县| 长治县| 梨树县| 巴林右旗| 龙山县| 满洲里市| 边坝县| 通榆县|