Android 通过XML的SearchView提示和动态的SearchView提示之间的区别
searchable.xml(需要使用SearchView小部件)和动态声明其提示之间有什么区别?为什么动态声明SearchView提示有效,但在XML文件中执行相同的操作却无法显示它 通过XMLAndroid 通过XML的SearchView提示和动态的SearchView提示之间的区别,android,xml,kotlin,searchview,android-search,Android,Xml,Kotlin,Searchview,Android Search,searchable.xml(需要使用SearchView小部件)和动态声明其提示之间有什么区别?为什么动态声明SearchView提示有效,但在XML文件中执行相同的操作却无法显示它 通过XML <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android"
<?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" />
因为
android:hint
是EditText
的提示(EditText
从TextView
继承,这是实现提示的视图,来自官方)
您要查找的属性是android:queryHint,您可以从官方网站上看到它
在Kotlin中,您直接设置变量,因为在Kotlin中不需要显式的getter和setter。变量名是解决问题的线索,类上的字段称为queryHint
nothint
searchView.queryHint = "Search"