mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Updating Menus catalog demo
PiperOrigin-RevId: 249279193
This commit is contained in:
parent
53abdffe40
commit
cc63b8672f
@ -18,6 +18,7 @@ package io.material.catalog.menu;
|
||||
|
||||
import io.material.catalog.R;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import dagger.Provides;
|
||||
@ -42,13 +43,21 @@ public class MenuFragment extends DemoLandingFragment {
|
||||
return R.string.cat_menus_description;
|
||||
}
|
||||
|
||||
|
||||
@LayoutRes
|
||||
public int getAdapterItemLayout() {
|
||||
return R.layout.cat_popup_item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Demo getMainDemo() {
|
||||
return new Demo() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Fragment createFragment() {
|
||||
return new MenuMainDemoFragment();
|
||||
MenuMainDemoFragment menuMainDemoFragment = new MenuMainDemoFragment();
|
||||
menuMainDemoFragment.setPopupItemLayoutRes(getAdapterItemLayout());
|
||||
return menuMainDemoFragment;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.InsetDrawable;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.MenuRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
@ -57,6 +58,7 @@ public class MenuMainDemoFragment extends DemoFragment {
|
||||
|
||||
private static final int ICON_MARGIN = 8;
|
||||
private static final String CLIP_DATA_LABEL = "Sample text to copy";
|
||||
@LayoutRes private int popupItemLayout;
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
|
||||
@ -167,13 +169,17 @@ public class MenuMainDemoFragment extends DemoFragment {
|
||||
});
|
||||
}
|
||||
|
||||
public void setPopupItemLayoutRes(@LayoutRes int popupItemRes) {
|
||||
popupItemLayout = popupItemRes;
|
||||
}
|
||||
|
||||
private ListPopupWindow initializeListPopupMenu(View v) {
|
||||
ListPopupWindow listPopupWindow =
|
||||
new ListPopupWindow(getContext(), null, R.attr.listPopupWindowStyle);
|
||||
ArrayAdapter<CharSequence> adapter =
|
||||
new ArrayAdapter<>(
|
||||
getContext(),
|
||||
R.layout.cat_popup_item,
|
||||
popupItemLayout,
|
||||
getResources().getStringArray(R.array.cat_list_popup_window_content));
|
||||
listPopupWindow.setAdapter(adapter);
|
||||
listPopupWindow.setAnchorView(v);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user