我试图在Android项目的搜索视图中捕获清除按钮事件:
SearchView _search = FindViewById<SearchView>(Resource.Id.publicSearchview);
_search.QueryTextSubmit += SearchBtn_Click;
ImageView _closeBtn = FindViewById<ImageView>(Resource.Id.search_close_btn);
_closeBtn.Click += CloseBtn_Click;
但_closeBtn始终为null。有什么建议??
<SearchView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/publicSearchview" />
答案 0 :(得分:1)
假设SearchView
未被设置为icon'fy,这将起作用:
var _search = FindViewById<SearchView>(Resource.Id.searchView1);
int searchCloseButtonId = _search.Context.Resources.GetIdentifier("android:id/search_close_btn", null, null);
var _closeBtn = FindViewById<ImageView>(searchCloseButtonId);
_closeBtn.Click += (object sender, EventArgs e) =>
{
Toast.MakeText(this, "Close Click", ToastLength.Long).Show();
};