這篇文章主要為大家展示了“android如何實(shí)現(xiàn)頂部toolbar搜索框”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“android如何實(shí)現(xiàn)頂部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的特性來完成的效果,并沒有添加其他什么邏輯。
以上是“android如何實(shí)現(xiàn)頂部toolbar搜索框”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前題目:android如何實(shí)現(xiàn)頂部toolbar搜索框-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://jinyejixie.com/article24/dichje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、網(wǎng)站營銷、面包屑導(dǎo)航、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容