View popupView = getLayoutInflater().inflate(R.layout.showlist, null); // 获取弹窗布局中的控件 TextView titleView = popupView.findViewById(R.id.title); TextView contentView = popupView.findViewById(R.id.content); // 设置弹窗标题和内容 titleView.setText("name"); contentView.setText(stringList.toString()); // 创建弹窗 PopupWindow popupWindow = new PopupWindow(popupView, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT); // 设置弹窗的背景和动画 popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popupWindow.setAnimationStyle(R.style.PopupAnimation); // 显示弹窗 popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);在弹窗中显示List<String>
时间: 2024-02-14 21:08:57 浏览: 346
可以将List<String>转换成字符串,然后将其设置为弹窗中的内容。代码如下:
```
List<String> stringList = new ArrayList<>();
// 将List<String>转换成字符串
String contentStr = TextUtils.join(", ", stringList);
// 获取弹窗布局中的控件
View popupView = getLayoutInflater().inflate(R.layout.showlist, null);
TextView titleView = popupView.findViewById(R.id.title);
TextView contentView = popupView.findViewById(R.id.content);
// 设置弹窗标题和内容
titleView.setText("name");
contentView.setText(contentStr);
// 创建弹窗
PopupWindow popupWindow = new PopupWindow(popupView,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT);
// 设置弹窗的背景和动画
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupWindow.setAnimationStyle(R.style.PopupAnimation);
// 显示弹窗
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
```
阅读全文