Skip to content

Commit 23aed17

Browse files
leticiarossidsn5ft
authored andcommitted
Updating Menus catalog demo.
PiperOrigin-RevId: 250284784
1 parent a9f135b commit 23aed17

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

catalog/java/io/material/catalog/menu/MenuFragment.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.material.catalog.R;
2020

21+
import androidx.annotation.LayoutRes;
2122
import androidx.annotation.Nullable;
2223
import androidx.fragment.app.Fragment;
2324
import dagger.Provides;
@@ -42,13 +43,21 @@ public int getDescriptionResId() {
4243
return R.string.cat_menus_description;
4344
}
4445

46+
47+
@LayoutRes
48+
public int getAdapterItemLayout() {
49+
return R.layout.cat_popup_item;
50+
}
51+
4552
@Override
4653
public Demo getMainDemo() {
4754
return new Demo() {
4855
@Nullable
4956
@Override
5057
public Fragment createFragment() {
51-
return new MenuMainDemoFragment();
58+
MenuMainDemoFragment menuMainDemoFragment = new MenuMainDemoFragment();
59+
menuMainDemoFragment.setPopupItemLayoutRes(getAdapterItemLayout());
60+
return menuMainDemoFragment;
5261
}
5362
};
5463
}

catalog/java/io/material/catalog/menu/MenuMainDemoFragment.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.content.Context;
2727
import android.graphics.drawable.InsetDrawable;
2828
import android.os.Bundle;
29+
import androidx.annotation.LayoutRes;
2930
import androidx.annotation.MenuRes;
3031
import androidx.annotation.Nullable;
3132
import com.google.android.material.snackbar.Snackbar;
@@ -57,6 +58,7 @@ public class MenuMainDemoFragment extends DemoFragment {
5758

5859
private static final int ICON_MARGIN = 8;
5960
private static final String CLIP_DATA_LABEL = "Sample text to copy";
61+
@LayoutRes private int popupItemLayout;
6062

6163
@Override
6264
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
@@ -167,13 +169,17 @@ public boolean onMenuItemClick(MenuItem item) {
167169
});
168170
}
169171

172+
public void setPopupItemLayoutRes(@LayoutRes int popupItemRes) {
173+
popupItemLayout = popupItemRes;
174+
}
175+
170176
private ListPopupWindow initializeListPopupMenu(View v) {
171177
ListPopupWindow listPopupWindow =
172178
new ListPopupWindow(getContext(), null, R.attr.listPopupWindowStyle);
173179
ArrayAdapter<CharSequence> adapter =
174180
new ArrayAdapter<>(
175181
getContext(),
176-
R.layout.cat_popup_item,
182+
popupItemLayout,
177183
getResources().getStringArray(R.array.cat_list_popup_window_content));
178184
listPopupWindow.setAdapter(adapter);
179185
listPopupWindow.setAnchorView(v);

lib/java/com/google/android/material/menu/res/values-v21/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<item name="android:overlapAnchor">true</item>
3232
</style>
3333

34-
<style name="Base.Widget.MaterialComponents.PopupMenu.ListPopupWindow" parent="Base.Widget.MaterialComponents.PopupMenu.ListPopupWindow">
34+
<style name="Base.Widget.MaterialComponents.PopupMenu.ListPopupWindow" parent="Widget.AppCompat.ListPopupWindow">
3535
<item name="android:popupBackground">@drawable/mtrl_popupmenu_background</item>
3636
<item name="android:popupElevation">8dp</item>
3737
<item name="android:overlapAnchor">true</item>

0 commit comments

Comments
 (0)