-1
A
回答
1
您可以爲此創建自定義佈局。 1.採取相對佈局,並給它一個圓形的邊框背景。 2.將漢堡包圖標添加到其中。 3.在右側添加麥克風圖標。 4.在中心添加edittext。 ,然後手動點擊漢堡圖標和麥克風圖標。
我有一些不完全相同的代碼,但您可以相應地編輯和更改它。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@drawable/editext_border">
<ImageView
android:id="@+id/iv_search_mic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_mic_green" />
<EditText
android:id="@+id/ed_home_searchbar"
fontPath="fonts/weblysleekuisl.ttf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/iv_search_icon"
android:layout_toRightOf="@+id/iv_search_mic"
android:background="@android:color/transparent"
android:hint="@string/action_search"
android:imeOptions="actionSearch"
android:padding="10dp"
android:singleLine="true"
android:textColor="@color/colorText"
android:textCursorDrawable="@drawable/color_cursor"
android:textSize="@dimen/text_xxsmall" />
<ImageView
android:id="@+id/iv_search_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_search_green" />
</RelativeLayout>
,然後處理像麥克風點擊
searchMic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OnSwap.getInstance().trackEvent(TAG, "searchMic", "searchMic Clicked");
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Search");
startActivityForResult(intent, VOICE_INPUT_REQUEST_CODE);
}
});
打開谷歌語音搜索,然後單擊事件onActivityResult方法
if (requestCode == VOICE_INPUT_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
int matchSize = matches.size();
for (int index = 0; index < matchSize; index++) {
Log.i(TAG, String.valueOf(index) + ": " + matches.get(index));
if (index == 0) {
searchbar.setText(matches.get(index));
}
}
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(this, data);
// TODO: Handle the error.
Log.i(TAG, status.getStatusMessage());
Snackbar.make(locationTextView, status.getStatusMessage(), Snackbar.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
Snackbar.make(locationTextView, "Canceled", Snackbar.LENGTH_LONG).show();
}
}
相關問題
- 1. 製作搜索引擎喜歡谷歌
- 2. 執行搜索喜歡谷歌搜索文本框
- 3. 如何實現谷歌通報人喜歡警報
- 4. 保護管理目錄從搜索引擎喜歡谷歌
- 5. 谷歌喜歡下拉框當用戶搜索
- 6. 谷歌喜歡搜索字符串解析爲sql
- 7. 如何實現像谷歌地圖搜索一樣的搜索?
- 8. 谷歌喜歡在SQL Server中使用全文搜索的搜索查詢
- 9. 谷歌搜索欄twitter-bootstrap
- 10. 谷歌搜索欄Android
- 11. 如何獲得客戶端地理位置喜歡谷歌搜索?
- 12. MYSQL喜歡搜索2表
- 13. PHP PDO喜歡(搜索)
- 14. 我如何實現「喜歡」按鈕?
- 15. 如何在android中實現搜索欄?
- 16. 如何在iPhone中實現搜索欄?
- 17. 如何實現實時多玩家谷歌玩遊戲服務C++到cocos2d-x
- 18. 搜索 - 如何實現谷歌網站搜索像這裏使用的一個
- 19. 實現「喜歡」功能
- 20. NoReverseMatch實現Django的喜歡
- 21. 對話框喜歡谷歌地圖Android
- 22. json.parse不喜歡谷歌地圖建議
- 23. 谷歌街景喜歡引擎
- 24. 谷歌喜歡下拉菜單
- 25. 在搜索欄中實現Google搜索
- 26. 谷歌CSE多重搜索欄問題
- 27. 搜索欄像谷歌在HTML和CSS
- 28. 谷歌sheets-環搜索欄,選擇拖
- 29. 如何在Android搜索欄模式中實現搜索模式?
- 30. 如何在UITableView中添加搜索欄喜歡iOS中的遊戲中心?
你可以在這裏讀到它:https://開頭開發商.android.com/guide/topics/search/search-dialog.html – REG1
[在操作欄中實現SearchView]的可能重複(http://stackoverflow.com/questions/21585326/implementing-searchview-in-action-bar) – JonasCz