2017-06-29 21 views
0

how to make a similiar design using Navigatiion drawer template activity ?アンドロイドスタジオのナビゲーションバーのタイトルに検索フィールドを追加する方法は?

+0

独自の 'AppBar'を定義し、'のEditTextが含まれますそれで。 – Dennis

+0

https://developer.android.com/guide/topics/search/search-dialog.html – Dennis

+0

これは 'SearchView'を使って行うことができます。レイアウトにSearchViewを追加し、ツールバーにレイアウトを追加し( 'android.support.v7.widget.Toolbar'、プロジェクトにandroid.support.v7を追加)、ツールバーを' supportActionBar'として設定します。 – Abhi

答えて

1

ちょうどあなたのツールバーの一部、このようなものとして、エディットテキストを追加します。

<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/primaryColor" 
android:elevation="4dp"> 

<EditText 
    android:id="@+id/searchEditText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    /> 
</android.support.v7.widget.Toolbar> 
0

このXMLコードを試してみてください。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout  
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.simple.activity.MainActivity"> 

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/coordinator_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/myAppBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:descendantFocusability="beforeDescendants" 
     android:focusableInTouchMode="true" 
     android:theme="@style/AppTheme.AppBarOverlay" 
     app:elevation="0dp"> 


     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <android.support.v7.widget.SearchView 
       android:id="@+id/search_view" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="8dp" 
       android:background="@color/white" 
        android:queryHint="@string/search_hint" 
       app:iconifiedByDefault="false" 
       app:theme="@style/AppTheme.SearchView" /> 

      <Button 
       android:id="@+id/button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="end" 
       android:background="@drawable/ic_arrow_forward_black_24dp"/> 
     </FrameLayout> 
     </android.support.design.widget.AppBarLayout> 
    </android.support.design.widget.CoordinatorLayout> 
</android.support.v4.widget.DrawerLayout> 
関連する問題