标签:
1 <?xml version="1.0" encoding="utf-8"?> 2 <searchable xmlns:android="http://schemas.android.com/apk/res/android" 3 android:label="@string/SearchLabel" 4 android:hint="@string/SearchPlaceHolder" 5 > 6 </searchable>
根节点 必须是 searchable 。
android:label 是必填项
android:hint 就是 html5 中的 placeholder
其它属选项请参考:
http://developer.android.com/guide/topics/search/searchable-config.html
1 <activity android:name="Search" > 2 <intent-filter> 3 <action android:name="android.intent.action.SEARCH" /> 4 </intent-filter> 5 <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/> 6 </activity> 7 8 <activity android:name=".MainActivity" > 9 <meta-data android:name="android.app.default_searchable" 10 android:value=".Search" /> 11 </activity>
1 [MetaData("android.app.searchable", Resource = "@xml/searchable")] 2 [IntentFilter(new[] { Intent.ActionSearch })] 3 [Activity(Label = "SearchActivity", Name = "aA.SearchA")] // aA.SearchA , aA为包名, 必须为小写字母开头 4 public class SearchActivity : Activity { 5 protected override void OnCreate(Bundle bundle) { 6 base.OnCreate(bundle); 7 8 9 if (this.Intent.Action.Equals(Intent.ActionSearch)) { 10 var query = this.Intent.GetStringExtra(SearchManager.Query); 11 Toast.MakeText(this, query, ToastLength.Short); 12 } 13 } 14 }
1 [MetaData("android.app.default_searchable", Value = "aA.SearchA")] 2 [Activity(Label = "Search", MainLauncher = true, Icon = "@drawable/icon")] 3 public class MainActivity : Activity {
其中 SearchActivity 上的 Activity 必须指定 Name, 而且必须是 xxx.xxx.xxx 的结构,如果只写 xxx , 编译会报错:缺少 package 名称。
Activity Name
Beginning with Xamarin.Android 5.1, the type name of an activity is based on the MD5SUM of the assembly-qualified name of the type being exported. This allows the same fully-qualified name to be provided from two different assemblies and not get a packaging error. (Before Xamarin.Android 5.1, the default type name of the activity was created from the lowercased namespace and the class name.)
If you wish to override this default and explicitly specify the name of your activity, use the
Name
property:
<activity android:icon="@drawable/icon" android:label="Search" android:name="md54b7a0ef5c9d7075d66a4a3ca71919313.MainActivity">?
要使用 Search Dialog 可见,需要在启用了 Search Dialog 的 Activity 上触发:onSearchRequested 方法。
1 private void Btn_Click(object sender, EventArgs e) { 2 this.OnSearchRequested(); 3 }
1 if (this.Intent.Action.Equals(Intent.ActionSearch)) { 2 var query = this.Intent.GetStringExtra(SearchManager.Query); 3 Toast.MakeText(this, query, ToastLength.Short); 4 }
1 public override bool OnSearchRequested() { 2 var bundle = new Bundle(); 3 bundle.PutBoolean("Key1", true); 4 this.StartSearch(null, false, bundle, false); 5 return true; 6 }
1 var bundle = intent.GetBundleExtra(SearchManager.AppData); 2 if (bundle != null) { 3 var key1 = bundle.GetBoolean("Key1"); 4 var key2 = bundle.GetBoolean("Key2"); 5 }
-------------
OK, 完
谢谢围观
Xamarin Android 的搜索框 : Search Dialog
标签:
原文地址:http://www.cnblogs.com/xling/p/Xamarin.html