【问题标题】:android - change icon of autocomplete_fragment in google mapsandroid - 在谷歌地图中更改自动完成片段的图标
【发布时间】:2016-12-26 07:46:50
【问题描述】:

我有一个使用谷歌地图的安卓应用,我想要一个看起来像安卓谷歌地图的搜索栏。下面是我的 XML 代码和我所拥有的图片。

 <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>

问题是我有一个导航抽屉,当您从左侧滑动时会打开。我想像谷歌地图一样将“三条水平线”添加到搜索栏,所以每当你点击它时,导航抽屉就会打开,如下所示。

那么如何将“放大镜”更改为“3 条水平线”并在点击时打开导航抽屉。谢谢!

【问题讨论】:

    标签: android google-maps navigation-drawer


    【解决方案1】:

    您可以找到对应的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();
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-08
      • 2016-06-07
      • 2012-12-05
      • 2017-08-16
      • 1970-01-01
      相关资源
      最近更新 更多