2016-12-25 2 views
2

Googleマップを使用したアンドロイドアプリがあり、アンドロイドのGoogleマップと同じように見える検索バーが必要でした。以下は私のXMLコードと私が持っているものの画像です。アンドロイド - googleマップのautocomplete_fragmentのアイコンを変更する

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="8dp"> 
    <fragment 
     android:id="@+id/place_autocomplete_fragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"/> 
</android.support.v7.widget.CardView> 

enter image description here

問題は、私はあなたが左からスライドしたときに開くナビゲーション引き出しを持っているということです。 Googleマップのように検索バーに「3つの水平線」を追加したいので、クリックするたびに以下のようにナビゲーションドロワーが開きます。

enter image description here

それでは、どのように私は「3本の水平線」に「虫眼鏡」に変更し、ナビゲーション引き出しがクリックで開くことができます。ありがとう!

答えて

2

あなたが対応するImageViewを見つけて、それのアイコンとクリックイベントに変更することができます。

PlaceAutocompleteFragment placeAutocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); 
ImageView searchIcon = (ImageView)((LinearLayout)placeAutocompleteFragment.getView()).getChildAt(0); 

// Set the desired icon 
searchIcon.setImageDrawable(getResources().getDrawable(R.drawable.yourdrawable)); 

// Set the desired behaviour on click 
searchIcon.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     Toast.makeText(MapsActivity.this, "YOUR DESIRED BEHAVIOUR HERE", Toast.LENGTH_SHORT).show(); 
    } 
}); 
+0

魔法のように働きました。ありがとうございました :) –

関連する問題