android.widget.ListPopupWindow#setContentWidth ( )源码实例Demo

下面列出了android.widget.ListPopupWindow#setContentWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TLint   文件: GalleryActivity.java
private void createPopupFolderList() {
    mFolderPopupWindow = new ListPopupWindow(this);
    mFolderPopupWindow.setAdapter(mFolderAdapter);
    mFolderPopupWindow.setContentWidth(ListPopupWindow.MATCH_PARENT);
    mFolderPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
    mFolderPopupWindow.setHeight(ListPopupWindow.MATCH_PARENT);
    mFolderPopupWindow.setAnchorView(toolbar);
    mFolderPopupWindow.setModal(true);
    mFolderPopupWindow.setAnimationStyle(R.style.popwindow_anim_style);
    mFolderPopupWindow.setOnItemClickListener(this);
}
 
源代码2 项目: home-assistant-Android   文件: SettingsActivity.java
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    View preferenceView = getListView().findViewHolderForAdapterPosition(preference.getOrder()).itemView;

    switch (preference.getKey()) {
        case Common.PREF_LOCATION_UPDATE_INTERVAL:
            ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
            listPopupWindow.setAnchorView(preferenceView);
            listPopupWindow.setAdapter(new ArrayAdapter<>(getActivity(), android.support.design.R.layout.support_simple_spinner_dropdown_item, getResources().getStringArray(R.array.location_update_interval_summaries)));
            listPopupWindow.setContentWidth(getResources().getDimensionPixelSize(R.dimen.popup_window_width));
            listPopupWindow.setHorizontalOffset(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin));
            listPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
                Log.d("Selected", String.valueOf(position));
                prefs.edit().putInt(Common.PREF_LOCATION_UPDATE_INTERVAL,
                        getResources().getIntArray(R.array.location_update_interval_values)[position]).apply();
                listPopupWindow.dismiss();
                updatePreferenceSummaries();
                updateLocationTracker();
            });
            listPopupWindow.show();
            return true;
        case Common.PREF_RESET_HOST_MISMATCHES:
            prefs.edit().remove(Common.PREF_ALLOWED_HOST_MISMATCHES_KEY).apply();
            Toast.makeText(getActivity(), R.string.toast_ignored_ssl_mismatches_cleared, Toast.LENGTH_SHORT).show();
            updatePreferenceSummaries();
            return true;
        case Common.HELP_TRANSLATE:
            CustomTabsSession session = ((SettingsActivity) getActivity()).getCustomTabsSession();
            if (session != null) {
                @SuppressWarnings("deprecation") CustomTabsIntent intent = new CustomTabsIntent.Builder(session)
                        .setShowTitle(true)
                        .enableUrlBarHiding()
                        .setToolbarColor(getResources().getColor(R.color.primary))
                        .build();
                intent.launchUrl(getActivity(), Uri.parse(Common.CROWDIN_URL));
            }
            return true;
        default:
            return super.onPreferenceTreeClick(preference);
    }
}
 
private void createPopupFolderList(int width, int height) {
	
    folderPopupWindow = new ListPopupWindow(getActivity());
    folderPopupWindow.setBackgroundDrawable(null);
    folderPopupWindow.setAdapter(folderAdapter);
    folderPopupWindow.setContentWidth(width);
    folderPopupWindow.setWidth(width);
    folderPopupWindow.setHeight(height * 5 / 8);
    folderPopupWindow.setAnchorView(popupAnchorView);
    folderPopupWindow.setModal(true);
    folderPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            folderAdapter.setSelectIndex(i);

            final int index = i;
            final AdapterView v = adapterView;

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    folderPopupWindow.dismiss();

                    if (index == 0) {
                        getActivity().getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
                        category_button.setText(R.string.all_folder);
                        callback.onChangeAlbum(context.getResources().getString(R.string.all_folder));
                        if (imageConfig.isShowCamera()) {
                            imageAdapter.setShowCamera(true);
                        } else {
                            imageAdapter.setShowCamera(false);
                        }
                    } 
                    else {
                        Folder folder = (Folder) v.getAdapter().getItem(index);
                        if (null != folder) {
                            imageList.clear();
                            imageList.addAll(folder.images);
                            imageAdapter.notifyDataSetChanged();

                            category_button.setText(folder.name);
                            callback.onChangeAlbum(folder.name);
                            if (resultList != null && resultList.size() > 0) {
                                imageAdapter.setDefaultSelected(resultList);
                            }
                        }
                        imageAdapter.setShowCamera(false);
                    }

                    grid_image.smoothScrollToPosition(0);
                }
            }, 100);
        }
    });
    
}