当前位置:网站首页>使用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窗口" />

边栏推荐
猜你喜欢

Mrs offline data analysis: process OBS data through Flink job

第3章业务功能开发(安全退出)

99%的人都不知道|私有化部署还永久免费的即时通讯软件!

网络攻防复习篇

Sator推出Web3游戏“Satorspace” ,并上线Huobi

策略模式 - Unity

Seaborn data visualization

How to choose the appropriate automated testing tools?

Sator a lancé le jeu web 3 "satorspace" et a lancé huobi

Biped robot controlled by Arduino
随机推荐
L1-025 正整数A+B(Lua)
[Seaborn] implementation of combined charts and multi subgraphs
Flask搭建api服务-生成API文档
使用Stace排除故障的5种简单方法
管理VDI的几个最佳实践
L1-028 判断素数(Lua)
Number of exchanges in the 9th Blue Bridge Cup finals
本周小贴士131:特殊成员函数和`= default`
LeetCode 1774. The dessert cost closest to the target price is one question per day
Test case management tool recommendation
Blue Bridge Cup final XOR conversion 100 points
第3章业务功能开发(安全退出)
无法链接远程redis服务器(解决办法百分百)
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
Matplotlib绘图界面设置
What is cloud computing?
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
【信息安全法律法規】複習篇
麒麟信安中标国网新一代调度项目!
如何在博客中添加Aplayer音乐播放器