我正在尝试按照此处的文档在Mono Android应用中实现搜索对话框:http: //developer.android.com/guide/topics/search/search-dialog.html
我有一个用户应该可以搜索的活动:
[Activity (Label = "MyActivity", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/MyStyle")]
[MetaData ("android.app.default_searchable", Value = ".SearchActivity")]
public class MainActivity : BaseActivity {...
Run Code Online (Sandbox Code Playgroud)
我有一个可搜索的活动(繁重的地方会发生):
[Activity(Theme = "@style/MyStyle", Label = "Searchable", LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]
[IntentFilter(new[] { Intent.ActionMain }, Categories = new[] { Intent.CategoryLauncher, Intent.ActionSearch })]
[MetaData("searchable", Resource = "@xml/searchable")]
public class SearchActivity : BaseActivity { ...
Run Code Online (Sandbox Code Playgroud)
我有我的searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable
xmlns:android="http://schemas.android.com/apk/res/android"
android:label="MyLabel"
android:hint="Search Products">
</searchable>
Run Code Online (Sandbox Code Playgroud)
当我在MainActivity中按下手机上的搜索键时,没有任何反应 - 没有对话框.我认为我的问题在于如何在运行时将属性转换为AndroidManifest.xml但我不确定.
更新2012年1月3日: 我已经发布了一个项目,该项目在这里被提炼为最基本的元素.按Android上的搜索按钮,您应该看到SearchDialog,但它没有出现:Demo Project Here
请注意,我使用的是Mono for Android
我有一个ListView项目,可以通过单击列表底部的"更多"按钮进行扩展.该列表以XML定义,但更多按钮只是一个可点击的TextView,它通过AddFooterView添加到列表的底部.我试图将预定义的样式应用于运行时创建的TextView但它无法正常工作.
mMoreProductsButton = new TextView(this, null, Resource.Style.more_button);
mMoreProductsButton.Text = "More";
mMoreProductsButton.Click += new EventHandler(MoreProductsButton_Click);
mListView.AddFooterView(mMoreProductsButton);
Run Code Online (Sandbox Code Playgroud)
TextView文档显示了此签名: TextView(Context context, AttributeSet attrs, int defStyle)
defStyle在文档中定义为要应用于视图的默认样式.我在别处看到的一个例子将null作为AttributeSet传递,但我不确定它是否有效或与我的问题有关.
我发现了这个错误,我不确定它是否相关且最新:http: //code.google.com/p/android/issues/detail?id = 12683
任何建议表示赞赏!