2017-08-08 5 views
0

バック矢印とsearchviewコンポーネントの間にスペースがある場所を理解しようとしています。私はツールチップで検索するために別のactivityを使用しています。Android:SearchViewのスペースを最小限にする

パディング0を検索ビューに追加しようとしましたが、成功しませんでした。検索activityに入っている間、私は、私の要件を満たすために開いているキーボードをカスタム検索ビューを作成し

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/search_toolbar_color" 
      app:popupTheme="@style/AppTheme.PopupOverlay" 
      android:padding="0dp" 
      app:theme="@style/ThemeOverlay.AppCompat.ActionBar" /> 

    </android.support.design.widget.AppBarLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


     <android.support.v7.widget.RecyclerView 
      android:id="@+id/search_results" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="3dp" 
      android:visibility="gone" /> 

    </RelativeLayout> 
</LinearLayout> 

、検索アイコンを削除し、colorスキーム

@Override 
    public boolean onCreateOptionsMenu(Menu menu) 
    { 
     getMenuInflater().inflate(R.menu.search_menu, menu); 
     MenuItem searchItem = menu.findItem(R.id.action_search); 

     SearchManager searchManager = (SearchManager) this.getSystemService(Context.SEARCH_SERVICE); 
     if (searchItem != null) 
     { 
      _searchView = (SearchView) searchItem.getActionView(); 
     } 

     if (_searchView != null) 
     { 
      _searchView.setSearchableInfo(searchManager.getSearchableInfo(this.getComponentName())); 
      _searchView.setQueryHint(getString(R.string.action_search)); 
      _searchView.setIconifiedByDefault(false); 
      final SearchView finalSearchView = _searchView; 
      _searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() 
      { 
       @Override 
       public void onFocusChange(View view, boolean hasFocus) 
       { 
        if (hasFocus) 
        { 
         //      showInputMethod(view); 
         finalSearchView.onActionViewExpanded(); 
        } 
       } 
      }); 


      //remove the icon in searchView 
      ImageView searchViewIcon = (ImageView) _searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon); 
      ViewGroup linearLayoutSearchView = (ViewGroup) searchViewIcon.getParent(); 
      linearLayoutSearchView.removeView(searchViewIcon); 

      _searchView.setOnQueryTextListener(this); 
      _searchView.requestFocus(); 

     } 
     return true; 
    } 

too big space

アップデート変更:

ビュー階層を使ってツールバーのレイアウトを検査した後、戻る矢印イメージと検索ビューとの間にある種のappcompat textviewがあります。残念ながら、私はそこからそれを削除する方法を知ることができません。

enter image description here

答えて

-1

私は私のために働いた解決策を見つけたあなたは、メニューのレイアウトを膨らまた後、私はこの行にonCreateOptionsMenuで

_searchView.setMaxWidth(Integer.MAX_VALUE); 

を追加しました。

あなたはもっとここで、[リンク]を読むことができます[1]

また、私は矢印とsearchviewの間にスペースがまだある

getSupportActionBar().setDisplayShowTitleEnabled(false); 

(*)を使用して、アクションバーからタイトルを削除それははるかに小さく、私はそれで生きることができます。

(**)GuilhermeFGL、残念ながら、あなたが提供したソリューションは私のために働いていませんでした。なぜなら、私はノーガットを実行しているからかもしれません。しかし、あなたの助けのためにthx。

0

あなたは(マージンネガ値を設定することができます)余分エスパスを最小限に抑えるためにToolbarにそれらの属性を設定することができます。

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    xmlns:app="schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@color/search_toolbar_color" 
    app:popupTheme="@style/AppTheme.PopupOverlay" 
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
    android:contentInsetLeft="0dp" 
    android:contentInsetStart="0dp" 
    app:contentInsetLeft="0dp" 
    app:contentInsetStart="0dp" 
    android:contentInsetRight="0dp" 
    android:contentInsetEnd="0dp" 
    app:contentInsetRight="0dp" 
    app:contentInsetEnd="0dp" /> 

オリジナルの答え:https://stackoverflow.com/a/32320632/8405762

代わりに使用することができますがSearchBar負のマージンのコンポーネント:

<android.support.v7.widget.SearchView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="-16dp" 
    android:paddingStart="-16dp" 
    app:iconifiedByDefault="false" 
    app:searchIcon="@null" 
    app:queryHint="Search" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark" /> 

SearchBar documentation

+0

残念ながら、機能しませんでした。ツールチップにスペースを取っているようなテキストビューがあります。最初の投稿で私の更新を見ることができます –

+0

'Toolbar'を' SearchView'に置き換えてみましょう。 'paddingLeft'を負の値で使って' TextView'を左に押します – GuilhermeFGL

関連する問題