2016-12-20 7 views
3

そうように私は、実行時の現在のビューにSearchViewを追加しています。ボタンが押されたときにSearchView AppBarを永久に上に移動しますか?

View searchpage = inflater.inflate(R.layout.search_ui, (ViewGroup) view.getParent(), false); 
    SearchView searchbar = (SearchView) searchpage.findViewById(R.id.searchbar); 
    //ViewGroup of current layout 
    parent.addView(searchbar); 

このコードが実行されます。

このコードは機能しますが、SearchViewを入力して終了すると、AppBarを上にシフトさせるアニメーションは終了してもAppBarがリセットされません。 SearchViewはAppBarに埋め込まれていないため、これを行うつもりはありません。 SearchViewをそのままAppBarの下に置いて欲しいです。

AppBarは別のxmlファイルで定義されています。私は、ViewPagerを使用して複数のビューを切り替えることにしています。検索バーは、そのようなXMLで定義されている

After SearchView is Tapped/Entered and Exited

Before SearchView is Tapped

<android.support.v7.widget.SearchView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/searchbar" 
     android:layout_below="@+id/view" 
     android:iconifiedByDefault="false" 
     android:queryHint="Search" 
     android:layout_centerHorizontal="true"> 

    </android.support.v7.widget.SearchView> 

アプリケーションバーがそうのように定義されています。

<android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay"> 

     </android.support.v7.widget.Toolbar> 
ここ

は、いくつかのスクリーンショットです

何か助けがあれば、私はAppBarが自動的に元に戻らない理由を忘れています。

EDIT:画面の下部に表示されないボタンのセットで問題が発生しました。私は彼らがnav barの下に引かれていることを理解しました。私は、SearchViewが入力されているときに、ツールバーが画面の最下部にある一連のボタンに対応するように上に押し出されていると思います。私はレイアウトにパディングを追加し、それが問題の解決策であると私は信じています。

おかげで、

-n.parker

+0

あなたの 'AndroidManifest'では、[' windowSoftInputMode'](https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft)を設定していますか? (もしそうなら、 'adjustPan'を使用していますか?) – Karakuri

+0

私はこれらのことをしていません。 –

+0

私はしません。それが原因である可能性がある場合に私は尋ねていました。 – Karakuri

答えて

-1

このような何かを試してみてください。

「layout」フォルダ内に、このようなtoolbar.xmlを作成します。

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorPrimary" 
    android:minHeight="?attr/actionBarSize"/> 

このツールバーは、他のアクティビティ(IDが必要)でも再利用できます。

+0

これは私の問題を解決する方法が混乱しています。私は、独自のxmlファイルからSearchViewをロードして、既にロードされているビューに追加しています。私はツールバーと同様のことをしなければならないでしょうか? –

+0

あなたは「SearchViewをそのままAppBarの下に置いて欲しい」と尋ねました。これが助けになるはずです。また、1つのファイルからツールバーをインポートし、個々のツールバーを作成しないようにすることをお勧めします。 – Zac1

関連する問題