Android弹出式提示框 PopupWindow
16lz
2021-12-04
Android 弹出消息提醒——PopupWindow。
public class MainActivity extends Activity { private PopupWindow pupWindow; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void showWindow(){ if(pupWindow == null){ LayoutInflater la = LayoutInflater.from(MainActivity.this); View view = la.inflate(R.layout.pupwindow, null);//自定义布局 tv = (TextView) view.findViewById(R.pupwindow.txt); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pupWindow.dismiss(); } }); pupWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT); } tv.setText("this is pup window!"); //设置PopupWindow的焦点 pupWindow.setFocusable(true); //点击PopupWindow之外的地方PopupWindow会消失 pupWindow.setOutsideTouchable(true); //showAtLocation(View parent, int gravity, int x, int y):相对于父控件的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以设置偏移或无偏移 pupWindow.showAtLocation(MainActivity.this.getWindow().getDecorView(), Gravity.CENTER, 0, 0); pupWindow.update(); }}
仅用于记录!
更多相关文章
- android > 弹出复选框
- Android切换横屏竖屏生命周期变化
- Android又一个超漂亮的日历控件
- Android(安卓)通用标题栏之组合控件
- android 全屏幕
- Android(安卓)计算控件尺寸
- android的常用控件总结【安卓入门五】
- Android(安卓)GridView,Gallery动态更新数据
- Android用悬浮按钮实现翻页效果