0

What's the difference between the searchable.xml (required to use SearchView widget) and declaring its hint dynamically? Why is it that declaring the SearchView hint dynamically works but doing the same thing in the XML file doesn't show it?

via XML

<?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" />

via Kotlin

searchView.queryHint = "Search"

1 Answer 1

0

Because android:hint is the hint for the EditText (EditText inherit from TextView which is the view implementing the hint, from the official documentation)

The attribute you are looking for is android:queryHint, you can see it from the official documentation

In the Kotlin way of doing it queryHint you are setting the variable directly because in Kotlin there is no explicit need for getters and setters. That variable name is the clue for figuring the problem, the field on the class is called queryHint not hint

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.