Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add metadata to activity in xamarin.android

How can I add the MetaData for searchable xml to an Activity using attributes in Xamarain.Android. Metadata that has to be added :-

<meta-data
    android:name="android.app.searchable"
    android:resource="@xml/searchable">
</meta-data>

Here I am making a android searchable Listview using ActionBar search Widget in Xamarin.Android. any help is appreciated. :)

like image 209
loop Avatar asked Sep 22 '14 13:09

loop


People also ask

How to create a Xamarin Android One activity to another activity passing value?

First Screen Give the Text Box Value “Hi Welcome" then Click Send Button.Next Move Second Screen. Second Screen to Press Get Button to Retrieve the passing value of “Hi Welcome” to display TextView. Finally, we have successfully created a Xamarin Android one activity to another activity passing value app.

How to create a blank app in Xamarin Android?

In this article you will create a Xamarin android one activity to another activity passing the value application. Step 1 - Open Visual Studio, New Project, Templates, Visual C#, Android, Blank App, then select Blank App. Give Project Name and Project Location.

What is Xamarin file in Android?

Xamarin. Android File Access with Xamarin. Android Using Android. Speech Xamarin. Essentials Xamarin. Android on Q&A Xamarin. Android AndroidManifest.xml is a powerful file in the Android platform that allows you to describe the functionality and requirements of your application to Android. However, working with it is not easy.

What is Xamarin Android binding tool?

Xamarin.Android provides a tool that generates these bindings. This tooling lets the developer control how a binding is created by using metadata, which allows procedures such as modifying namespaces and renaming members.


2 Answers

There is a MetaDataAttribute that you can add to your Activity.

[Activity]
[MetaData("android.app.searchable", Resource="@xml/searchable")]
public class MyActivity : Activity
{
}
like image 63
kevskree Avatar answered Oct 10 '22 11:10

kevskree


You probably need to add both IntentFilterAttribute and MetaDataAttribute

Following solution works fine for me:

[Activity (...)]
[IntentFilter(new[]{Intent.ActionSearch})]
[MetaData("android.app.searchable", Resource="@xml/searchable")]

public class MainActivity : Activity
{

... }

Good explanation how to add search functionality can be found here: http://codetheory.in/adding-search-to-android/

like image 40
Inka Avatar answered Oct 10 '22 11:10

Inka