Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searchable.xml for Android Studio, place where?

Tags:

android

xml

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

like image 523
user3352131 Avatar asked Aug 03 '14 17:08

user3352131


People also ask

Where is the XML file in Android Studio?

xml extension, in your Android project's res/layout/ directory, so it will properly compile. More information about the syntax for a layout XML file is available in the Layout Resources document.

Where is xml used in Android?

XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.

Where is activity main xml in Android Studio?

In the Project window, open app > res > layout > activity_main. xml.


3 Answers

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.

like image 195
Kapil Rajput Avatar answered Oct 12 '22 02:10

Kapil Rajput


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>
like image 8
LaraChícharo Avatar answered Oct 12 '22 00:10

LaraChícharo


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

like image 3
Vinoth Vino Avatar answered Oct 12 '22 01:10

Vinoth Vino