Skip to content

Commit 9bda9a9

Browse files
imhappihunterstich
authored andcommitted
[Searchbar] Add a demo with 2 icons outside the searchbar
PiperOrigin-RevId: 730992169
1 parent 580e8d5 commit 9bda9a9

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed

catalog/java/io/material/catalog/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@
110110
android:name="io.material.catalog.search.SearchRecyclerDemoActivity"
111111
android:windowSoftInputMode="adjustNothing"
112112
android:exported="true" />
113+
<activity
114+
android:name="io.material.catalog.search.SearchBarWithOutsideIconsDemoActivity"
115+
android:windowSoftInputMode="adjustNothing"
116+
android:exported="true" />
113117
</application>
114118

115119
</manifest>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.material.catalog.search;
18+
19+
import io.material.catalog.R;
20+
21+
import android.os.Bundle;
22+
import android.view.LayoutInflater;
23+
import android.view.View;
24+
import android.view.ViewGroup;
25+
import android.widget.LinearLayout;
26+
import androidx.annotation.NonNull;
27+
import androidx.annotation.Nullable;
28+
import com.google.android.material.search.SearchBar;
29+
import com.google.android.material.search.SearchView;
30+
import io.material.catalog.feature.DemoActivity;
31+
32+
/** An activity that displays a Searchbar in an Appbar with outside icons demo. */
33+
public class SearchBarWithOutsideIconsDemoActivity extends DemoActivity {
34+
35+
@Nullable
36+
@Override
37+
public View onCreateDemoView(
38+
@NonNull LayoutInflater layoutInflater,
39+
@Nullable ViewGroup viewGroup,
40+
@Nullable Bundle bundle) {
41+
View view = layoutInflater.inflate(R.layout.cat_search_appbar_icons_fragment, viewGroup, false);
42+
43+
SearchBar searchBar = view.findViewById(R.id.cat_search_bar);
44+
SearchView searchView = view.findViewById(R.id.cat_search_view);
45+
LinearLayout suggestionContainer = view.findViewById(R.id.cat_search_view_suggestion_container);
46+
47+
searchView.setupWithSearchBar(searchBar);
48+
SearchDemoUtils.setUpSearchView(this, searchBar, searchView);
49+
SearchDemoUtils.setUpSuggestions(suggestionContainer, searchBar, searchView);
50+
SearchDemoUtils.startOnLoadAnimation(searchBar, bundle);
51+
52+
return view;
53+
}
54+
55+
@Override
56+
protected boolean shouldShowDefaultDemoActionBar() {
57+
return false;
58+
}
59+
}

catalog/java/io/material/catalog/search/SearchFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ public Intent createActivityIntent() {
6969
return new Intent(getContext(), SearchRecyclerDemoActivity.class);
7070
}
7171
});
72+
additionalDemos.add(
73+
new Demo(R.string.cat_searchbar_outside_icon_title) {
74+
@Override
75+
public Intent createActivityIntent() {
76+
return new Intent(getContext(), SearchBarWithOutsideIconsDemoActivity.class);
77+
}
78+
});
7279
return additionalDemos;
7380
}
7481

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<androidx.coordinatorlayout.widget.CoordinatorLayout
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent"
22+
android:fitsSystemWindows="true">
23+
24+
<com.google.android.material.appbar.AppBarLayout
25+
android:id="@+id/app_bar_layout"
26+
android:layout_width="match_parent"
27+
android:layout_height="wrap_content"
28+
android:fitsSystemWindows="true"
29+
app:statusBarForeground="?attr/colorSurface">
30+
31+
<LinearLayout
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:layout_gravity="center_vertical">
35+
<ImageView
36+
android:id="@+id/product_logo"
37+
android:layout_width="48dp"
38+
android:layout_height="48dp"
39+
android:scaleType="center"
40+
android:layout_marginStart="4dp"
41+
android:layout_marginEnd="8dp"
42+
android:contentDescription="@string/cat_searchbar_home_icon_description"
43+
android:layout_gravity="center_vertical"
44+
android:src="@drawable/ic_home_default_24px"/>
45+
<com.google.android.material.search.SearchBar
46+
android:id="@+id/cat_search_bar"
47+
android:layout_width="0dp"
48+
android:layout_height="wrap_content"
49+
android:layout_weight="1"
50+
android:layout_marginVertical="4dp"
51+
android:layout_gravity="center_vertical"
52+
app:defaultMarginsEnabled="false"
53+
android:hint="@string/cat_searchbar_hint"/>
54+
<ImageView
55+
android:layout_width="48dp"
56+
android:layout_height="48dp"
57+
android:scaleType="center"
58+
android:layout_marginStart="8dp"
59+
android:layout_marginEnd="4dp"
60+
android:contentDescription="@string/cat_searchbar_cast_icon_description"
61+
android:layout_gravity="center_vertical"
62+
android:src="@drawable/ic_cast_vd_theme_24" />
63+
</LinearLayout>
64+
65+
</com.google.android.material.appbar.AppBarLayout>
66+
67+
<androidx.core.widget.NestedScrollView
68+
android:id="@+id/nested_scroll_view"
69+
android:layout_width="match_parent"
70+
android:layout_height="match_parent"
71+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
72+
73+
<TextView
74+
android:layout_width="match_parent"
75+
android:layout_height="wrap_content"
76+
android:layout_margin="16dp"
77+
android:lineSpacingMultiplier="1.2"
78+
android:text="@string/cat_searchbar_lorem_ipsum"/>
79+
</androidx.core.widget.NestedScrollView>
80+
81+
<com.google.android.material.search.SearchView
82+
android:id="@+id/cat_search_view"
83+
android:layout_width="match_parent"
84+
android:layout_height="match_parent"
85+
android:hint="@string/cat_searchbar_hint"
86+
app:layout_anchor="@id/cat_search_bar">
87+
88+
<!-- Content goes here (ScrollView, RecyclerView, etc.). -->
89+
<ScrollView
90+
android:layout_width="match_parent"
91+
android:layout_height="match_parent"
92+
android:scrollbars="none">
93+
94+
<LinearLayout
95+
android:id="@+id/cat_search_view_suggestion_container"
96+
android:layout_width="match_parent"
97+
android:layout_height="wrap_content"
98+
android:orientation="vertical"/>
99+
</ScrollView>
100+
</com.google.android.material.search.SearchView>
101+
</androidx.coordinatorlayout.widget.CoordinatorLayout>

catalog/java/io/material/catalog/search/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
description="Title for trips tab.[CHAR_LIMIT=40]">Trips</string>
7070
<string name="cat_searchbar_recycler_title"
7171
description="Title for recycler view demo.[CHAR_LIMIT=100]">RecyclerView Demo</string>
72+
<string name="cat_searchbar_outside_icon_title"
73+
description="Title for Searchbar with outside icons demo.[CHAR_LIMIT=NONE]">Searchbar Demo with Outside Icons</string>
7274
<string name="cat_searchbar_recycler_item_title_prefix"
7375
description="Title for recycler item.[CHAR_LIMIT=40]">Message</string>
7476

@@ -86,5 +88,9 @@
8688
<string name="cat_searchbar_nav_drawer_user"
8789
description="Label for username display text.[CHAR_LIMIT=NONE]">User</string>
8890
<string name="cat_searchbar_nav_drawer_email" translatable="false">[email protected]</string>
91+
<string name="cat_searchbar_home_icon_description"
92+
description="Description about a home icon button.[CHAR_LIMIT=NONE]">Home</string>
93+
<string name="cat_searchbar_cast_icon_description"
94+
description="Description about a cast icon button.[CHAR_LIMIT=NONE]">Cast</string>
8995

9096
</resources>

0 commit comments

Comments
 (0)