2016-12-25 43 views
2

我有一個使用谷歌地圖的Android應用程序,我想要一個搜索欄,看起來就像android谷歌地圖。以下是我的XML代碼和我所擁有的圖片。android - 在谷歌地圖中更改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

的問題是,我有,當你從左側滑動打開抽屜式導航。我想添加「三條橫線」到谷歌地圖等搜索欄,所以無論何時單擊,都會打開如下所示的抽屜式導航欄。

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

也就是說,像變魔術一樣。謝謝 :) –