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
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.
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.
In the Project window, open app > res > layout > activity_main. xml.
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.
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With