Home » Android » Searchable.xml for Android Studio, place where?

Searchable.xml for Android Studio, place where?

Posted by: admin June 15, 2020 Leave a comment

Questions:

Where do you add searchable.xml in Android Studio, under layout, values, where? When adding “new xml file” only have layout or values as options. Any 2014 example code?
Android Studio gives error for this:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
    android:hint="@string/search_hint" />

error: “searchable” element doesn’t have required attribute “http:…..”

Android Studio does not seem to recognize “<searchable/>” as a resource

How to&Answers:

Rigth click to ‘res’, ‘new android resource file’.
Filename ‘searchable.xml’, resource type xml, ‘ok’.

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_label"
    android:hint="@string/search_hint" >
</searchable>

On AndroidManifest.xml add next code inside ‘application’ label.

<activity android:name="search.search_class">
    <intent-filter>
        <action android:name="android.intent.action.SEARCH"/>
    </intent-filter>
        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" <---
                />
</activity>

Answer:

Step by Step Solution :

Step 1 : Right click on res > New > Android resource directory

Step 2 : Popup will open choose Directory name as xml and Resource type as xml

Step 3 : Then xml Directory will be created in res folder, Right click on xml > New > XML resource file

Step 4 : popup will open set file name as searchable.xml and Root element as searchable

searchable.xml is created do your code then.

Answer:

You have to create a folder called xml in res folder of your android project and place your searchable.xml file into xml folder

`XML file saved at res/xml/searchable.xml:`

Do like this below

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint" />

In AndroidManifest.xml

 <activity android:name=".MainActivity"
        android:label="@string/title_activity_main">
    <meta-data
        android:name="android.app.searchable"
        android:resource="@xml/searchable"/> <!-- Your searchable file -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Hope this helps you…

See this for more info