Reputation: 87
In my Android application, there is a single main Activity with two Fragments. in one of them, I want to create the InstantSearch.
I'm trying to follow the InstantSearch guide but the androidx.appcompat.widget.Toolbar
doesn't appear at all.
Here is my layout file for this Fragment:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_height="?attr/actionBarSize">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:iconifiedByDefault="false" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<TextView
android:id="@+id/stats"
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="16dp"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/memory_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
</androidx.recyclerview.widget.RecyclerView>
<RelativeLayout 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:layout_below="@+id/toolbar"
xmlns:fab="http://schemas.android.com/apk/res-auto"
tools:context="com.memoryDiary.Fragment.MemoryFragment"
android:padding="8dp">
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/add_memory_fab_menu"
android:layout_width="297dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:clickable="true"
fab:menu_animationDelayPerItem="50"
fab:menu_backgroundColor="@android:color/transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="@color/babyBlue"
fab:menu_colorPressed="@color/red"
fab:menu_colorRipple="#99FFFFFF"
fab:menu_fab_hide_animation="@anim/fab_slide_out_to_right"
fab:menu_fab_show_animation="@anim/fab_slide_in_from_right"
fab:menu_fab_size="normal"
fab:menu_icon="@drawable/ic_add_white_24dp"
fab:menu_labels_colorNormal="#333333"
fab:menu_labels_colorPressed="#444444"
fab:menu_labels_colorRipple="#66FFFFFF"
fab:menu_labels_cornerRadius="3dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="8dp"
fab:menu_labels_paddingBottom="4dp"
fab:menu_labels_paddingLeft="8dp"
fab:menu_labels_paddingRight="8dp"
fab:menu_labels_paddingTop="4dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="true"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#FFFFFF"
fab:menu_labels_textSize="14sp"
fab:menu_openDirection="up"
fab:menu_shadowColor="#66000000"
fab:menu_shadowRadius="4dp"
fab:menu_shadowXOffset="1dp"
fab:menu_shadowYOffset="3dp">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/add_memory_fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_insert_comment_white_24dp"
fab:fab_label="Create Memory"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/add_memory_fab_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_search_white_24dp"
fab:fab_label="Search"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/add_memory_fab_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_logout_new_white_24dp"
fab:fab_label="Logout"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
My app build.gradle file includes implementation 'androidx.appcompat:appcompat:1.0.0'
dependency.
In addition, I changed the style.xml file to have Theme.AppCompat.Light.NoActionBar
instead of Theme.AppCompat.Light.DarkActionBar
.
What could be the reason for toolbar doesn't show up?
Thanks for helping.
EDIT: As @Mayur Patel say, I had the wrong constraint to my RelativeLayout and now the problem is that androidx.appcompat.widget.SearchView
doesn't appear.
Upvotes: 0
Views: 1490
Reputation: 2326
You have given the wrong constraint to your RelativeLayout.
Try this way:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="false"
app:iconifiedByDefault="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<TextView
android:id="@+id/stats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="16dp"
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/memory_recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/toolbar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="@+id/stats">
</androidx.recyclerview.widget.RecyclerView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="@+id/stats">
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/add_memory_fab_menu"
android:layout_width="297dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:clickable="true"
app:menu_animationDelayPerItem="50"
app:menu_backgroundColor="@android:color/transparent"
app:menu_buttonSpacing="0dp"
app:menu_colorNormal="@color/babyBlue"
app:menu_colorPressed="@color/red"
app:menu_colorRipple="#99FFFFFF"
app:menu_fab_hide_animation="@anim/fab_slide_out_to_right"
app:menu_fab_show_animation="@anim/fab_slide_in_from_right"
app:menu_fab_size="normal"
app:menu_icon="@drawable/ic_add_white_24dp"
app:menu_labels_colorNormal="#333333"
app:menu_labels_colorPressed="#444444"
app:menu_labels_colorRipple="#66FFFFFF"
app:menu_labels_cornerRadius="3dp"
app:menu_labels_ellipsize="none"
app:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
app:menu_labels_margin="0dp"
app:menu_labels_maxLines="-1"
app:menu_labels_padding="8dp"
app:menu_labels_paddingBottom="4dp"
app:menu_labels_paddingLeft="8dp"
app:menu_labels_paddingRight="8dp"
app:menu_labels_paddingTop="4dp"
app:menu_labels_position="left"
app:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
app:menu_labels_showShadow="true"
app:menu_labels_singleLine="false"
app:menu_labels_textColor="#FFFFFF"
app:menu_labels_textSize="14sp"
app:menu_openDirection="up"
app:menu_shadowColor="#66000000"
app:menu_shadowRadius="4dp"
app:menu_shadowXOffset="1dp"
app:menu_shadowYOffset="3dp">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/add_memory_fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_insert_comment_white_24dp"
app:fab_label="Create Memory"
app:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/add_memory_fab_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_search_white_24dp"
app:fab_label="Search"
app:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/add_memory_fab_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_logout_new_white_24dp"
app:fab_label="Logout"
app:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 2