当前位置:网站首页>使用popupwindow創建对话框风格的窗口
使用popupwindow創建对话框风格的窗口
2022-07-07 15:40:00 【XLMN】
使用popupwindow創建对话框风格的窗口
public class MainActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popupwindow);
// 加载r.layout.popup对应的布局文件
View root = this.getLayoutInflater().inflate(R.layout.popup, null);
//創建popupwindow对象
final PopupWindow pw = new PopupWindow(root, 1560, 1720);
Button bt = findViewById(R.id.button2);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 以下拉的方式显示
pw.showAsDropDown(v);
//将popupwindow显示在指定的位置
pw.showAtLocation(findViewById(R.id.button2), Gravity.CENTER, 20, 20);
}
});
//获取popupwindow中关闭按钮
root.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//关闭popupwindow
pw.dismiss();
}
});
}
}
<ImageView
android:layout_width="wrap_content"
android:layout_height="560dp"
android:src="@drawable/mia1" />
<Button
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="关闭" />
<?xml version="1.0" encoding="utf-8"?> <Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="弹出popop窗口" />
边栏推荐
- First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
- 第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
- Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
- 99% of users often make mistakes in power Bi cloud reports
- Proxmox VE重装后,如何无损挂载原有的数据盘?
- Enum + Validation 的个人最佳实践 demo 分享
- [Seaborn] combination chart: pairplot and jointplot
- mysql实现两个字段合并成一个字段查询
- LeetCode 497(C#)
- Flask搭建api服务
猜你喜欢
随机推荐
Sator launched Web3 game "satorspace" and launched hoobi
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
The top of slashdata developer tool is up to you!!!
第3章业务功能开发(用户访问项目)
Solid function learning
防火墙系统崩溃、文件丢失的修复方法,材料成本0元
A tour of grpc:03 - proto serialization / deserialization
Rpcms method of obtaining articles under the specified classification
Biped robot controlled by Arduino
LeetCode1051(C#)
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
LeetCode 1654. The minimum number of jumps to get home one question per day
rpcms获取指定分类下的文章的方法
【网络攻防原理与技术】第7章:口令攻击技术 第8章:网络监听技术
【网络攻防原理与技术】第6章:特洛伊木马
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
DevOps 的运营和商业利益指南
【网络攻防原理与技术】第1章:绪论
专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
The mail server is listed in the blacklist. How to unblock it quickly?