mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
[TopAppBar] Added a demo to show case using collapsing toolbar layout with a toggleable button; reduced the number of menu items in all demos.
PiperOrigin-RevId: 708397663
This commit is contained in:
parent
94966194fa
commit
8726702fa2
@ -31,7 +31,7 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
import io.material.catalog.feature.DemoFragment;
|
||||
|
||||
/**
|
||||
* A fragment that displays a large Collapsing Toolbar Top App Bar with a filled action button demo
|
||||
* A fragment that displays a medium Collapsing Toolbar Top App Bar with a filled action button demo
|
||||
* for the Catalog app.
|
||||
*/
|
||||
public class TopAppBarCollapsingFilledActionDemoFragment extends DemoFragment {
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.material.catalog.topappbar;
|
||||
|
||||
import io.material.catalog.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import io.material.catalog.feature.DemoFragment;
|
||||
|
||||
/**
|
||||
* A fragment that displays a medium Collapsing Toolbar Top App Bar with a toggleable action button
|
||||
* demo for the Catalog app.
|
||||
*/
|
||||
public class TopAppBarCollapsingToggleableActionDemoFragment extends DemoFragment {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateDemoView(
|
||||
@NonNull LayoutInflater layoutInflater,
|
||||
@Nullable ViewGroup viewGroup,
|
||||
@Nullable Bundle bundle) {
|
||||
View view =
|
||||
layoutInflater.inflate(
|
||||
R.layout.cat_topappbar_collapsing_toggleable_action_fragment, viewGroup, false);
|
||||
|
||||
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
activity.setSupportActionBar(toolbar);
|
||||
|
||||
MaterialButton actionButton = view.findViewById(R.id.action_button);
|
||||
actionButton.setOnClickListener(
|
||||
v ->
|
||||
Snackbar.make(
|
||||
v,
|
||||
(actionButton.isChecked() ? "Marked as favorite." : "Marked as not favorite"),
|
||||
Snackbar.LENGTH_SHORT)
|
||||
.show());
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldShowDefaultDemoActionBar() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -139,6 +139,13 @@ public class TopAppBarFragment extends DemoLandingFragment {
|
||||
public Fragment createFragment() {
|
||||
return new TopAppBarCollapsingFilledActionDemoFragment();
|
||||
}
|
||||
},
|
||||
new Demo(R.string.cat_topappbar_collapsing_with_toggleable_action_demo_title) {
|
||||
@Nullable
|
||||
@Override
|
||||
public Fragment createFragment() {
|
||||
return new TopAppBarCollapsingToggleableActionDemoFragment();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2024 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/coordinator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbarlayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
style="?attr/collapsingToolbarLayoutMediumStyle"
|
||||
android:id="@+id/collapsingtoolbarlayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/collapsingToolbarLayoutMediumWithSubtitleSize"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
|
||||
app:expandedTitleGravity="bottom|center_horizontal"
|
||||
app:title="@string/cat_topappbar_collapsing_demo_toolbar_medium_title"
|
||||
app:subtitle="@string/cat_topappbar_collapsing_demo_toolbar_medium_subtitle"
|
||||
app:toolbarId="@id/toolbar">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_collapseMode="pin">
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="?attr/catalogToolbarWithCloseButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:layout_weight="1"
|
||||
android:elevation="0dp"/>
|
||||
<Button
|
||||
android:id="@+id/action_button"
|
||||
style="?attr/materialIconButtonFilledStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:checkable="true"
|
||||
app:icon="@drawable/ic_favorite_checkable_24px"/>
|
||||
</LinearLayout>
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<include layout="@layout/cat_topappbar_filler_text_view"/>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@ -19,7 +19,8 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:ignore="AppCompatResource">
|
||||
<item
|
||||
android:id="@+id/cat_topappbar_item_edit"
|
||||
android:id="@+id/cat_topappbar_item_edit"
|
||||
android:icon="@drawable/ic_edit_vd_theme_24dp"
|
||||
android:title="@string/cat_topappbar_edit_menu_item_title"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
@ -27,10 +28,4 @@
|
||||
android:icon="@drawable/ic_favorite_vd_theme_24px"
|
||||
android:title="@string/cat_topappbar_favorite_menu_item_title"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:title="@string/cat_topappbar_settings_menu_item_title"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:title="@string/cat_topappbar_help_and_feedback_menu_item_title"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
<string name="cat_topappbar_collapsing_large_demo_title" translatable="false">Collapsing Demo (Large)</string>
|
||||
<string name="cat_topappbar_collapsing_large_with_subtitle_demo_title" translatable="false">Collapsing with Subtitle Demo (Large)</string>
|
||||
<string name="cat_topappbar_collapsing_with_filled_action_demo_title" translatable="false">Collapsing Demo (Filled Action)</string>
|
||||
<string name="cat_topappbar_collapsing_with_toggleable_action_demo_title" translatable="false">Collapsing Demo (Toggleable Action)</string>
|
||||
<string name="cat_topappbar_collapsing_multiline_demo_title" translatable="false">Collapsing Demo (Multiline title)</string>
|
||||
<string name="cat_topappbar_toolbar_title" translatable="false">Toolbar Demo</string>
|
||||
<string name="cat_topappbar_action_bar_title" translatable="false">Action Bar Demo</string>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user