英文:
Why does my Searchview doesn't display the queryHint in android using androidx?
问题
以下是要翻译的代码部分:
<!-- Add the Toolbar -->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/flash_tablebar"
android:title="Lingo"
android:titleTextColor="@color/new_design_darker_shade">
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="40dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:background="#FFFF"
android:queryHint="Search..."
android:textColorHint="@android:color/black"
android:iconifiedByDefault="false"/>
</androidx.appcompat.widget.Toolbar>
<!-- NestedScrollView to contain the GridView and make it scrollable -->
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<!-- Your GridView -->
<GridView
android:id="@+id/mainSpecimens"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?android:actionBarSize"
android:clipToPadding="false"
android:horizontalSpacing="6dp"
android:numColumns="3"
android:verticalSpacing="6dp" />
</androidx.core.widget.NestedScrollView>
希望这可以帮助您解决搜索视图中查询提示不显示的问题。
英文:
I have a searchView in the Toolbar which also has Gridview elements. Everything works fine except the queryHint doesn't get displayed in the searchView. I have tried setting android:iconifiedByDefault="false" but the issue persists. Below is the code of activity's layout.
firstscreen.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.activities.FirstScreen">
<!-- android:numColumns=2 is the number of columns for Grid View
android:horizontalSpacing is the space between horizontal grid items -->
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/bottomNavigationView"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:background="@color/bottomNavigation"
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="66dp"
app:layout_insetEdge="bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_navigation_menu"/>
</androidx.constraintlayout.widget.ConstraintLayout>
And this is my fragment's xml layout where the searchview is added.
fragment_user.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Add the Toolbar -->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/flash_tablebar"
android:title="Lingo"
android:titleTextColor="@color/new_design_darker_shade">
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="40dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:background="#FFFF"
android:queryHint="Search..."
android:textColorHint="@android:color/black"
android:iconifiedByDefault="false"/>
</androidx.appcompat.widget.Toolbar>
<!-- NestedScrollView to contain the GridView and make it scrollable -->
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<!-- Your GridView -->
<GridView
android:id="@+id/mainSpecimens"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?android:actionBarSize"
android:clipToPadding="false"
android:horizontalSpacing="6dp"
android:numColumns="3"
android:verticalSpacing="6dp" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
答案1
得分: 1
app:queryHint="Search..."
app:iconifiedByDefault="false"
英文:
you should change tag of queryHint and iconifiedByDefault form android to app.
app:queryHint="Search..."
app:iconifiedByDefault="false"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论