我已在Google Place Autocomplete API
成功整合Activity
。新流程应该是这样的:
Menu search
图标。Google place autocomplete
的搜索框应与其对齐。autocomplete
。它应该更新Menu search Icon
。以下是代码:
...
<item android:id="@+id/search"
android:title="@string/action_search"
android:icon="@drawable/ic_search"
android:orderInCategory="100"
app:showAsAction="always" />
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_add_location, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.search) {
// Method #3
try {
Intent intent = new PlaceAutocomplete.IntentBuilder
(PlaceAutocomplete.MODE_FULLSCREEN)
.setBoundsBias(BOUNDS_MOUNTAIN_VIEW)
.build(AddLocationActivityNew.this);
startActivityForResult(intent, REQUEST_SELECT_PLACE);
} catch (GooglePlayServicesRepairableException |
GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onPlaceSelected(Place place) {
Log.i(LOG_TAG, "Place Selected: " + place.getName());
txt_location.setText(getString(R.string.formatted_place_data, place
.getName(), place.getAddress(), place.getPhoneNumber(), place
.getWebsiteUri(), place.getRating(), place.getId()));
if (!TextUtils.isEmpty(place.getAttributions())){
txt_attributions.setText(Html.fromHtml(place.getAttributions().toString()));
}
}
如何将此活动整合到操作栏中?
如果我将MODE
从FullScreen更改为Overlays。它是这样的:
如何在Android操作栏中集成整个搜索栏?
答案 0 :(得分:0)
在菜单文件中定义搜索按钮时,请尝试使用app:actionViewClass="android.support.v7.widget.SearchView"