View popupView = getLayoutInflater().inflate(R.layout.showlist, null); // 获取弹窗布局中的控件 TextView contentView = popupView.findViewById(R.id.content); contentView.setMovementMethod(new ScrollingMovementMethod()); // 设置弹窗内容 String symbols = numbered.toString(); symbols = symbols.replace("[", ""); // 去掉 [ symbols = symbols.replace("]", ""); // 去掉 ] symbols = symbols.replaceAll("\\s", ""); // 去掉空格 String output = symbols.replaceAll(",", "\n"); contentView.setText(output); // 创建弹窗 PopupWindow popupWindow = new PopupWindow(popupView, 550, WindowManager.LayoutParams.WRAP_CONTENT); // 设置弹窗的背景和动画 popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popupWindow.setAnimationStyle(R.style.PopupAnimation); // 设置弹窗的属性 popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); // 显示弹窗 popupWindow.showAtLocation(view, Gravity.CENTER, 1000, 0);给弹窗加边框
时间: 2024-02-14 14:10:02 浏览: 149
Android getViewById和getLayoutInflater().inflate()的详解及比较
要给弹窗加边框,可以在弹窗布局文件中添加一个边框样式,例如:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<stroke
android:width="2dp"
android:color="#000000" />
</shape>
```
然后在弹窗布局文件的根布局中设置该边框样式:
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/popup_border"
android:orientation="vertical">
<!-- 弹窗内容 -->
</LinearLayout>
```
其中,`@drawable/popup_border` 是指边框样式的资源文件。这样就可以在弹窗周围加上边框了。
阅读全文