-
Android PopupWindow弹出对话框的实现
Java代码
- package com.easyway.ui.popupWindow;
-
- import android.app.Activity;
- import android.content.Context;
- import android.os.Bundle;
- import android.view.Gravity;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.PopupWindow;
-
- /**
- * PopupWindow弹出对话框的实现
- *
- * //获取布局管理对象
- * LayoutInflater inflater = (LayoutInflater)
- * context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- * //获取相关的自定义布局视图
- * final View vPopupWindow=inflater.inflate(R.layout.popupwindow, null, false);
- * //PopupWindow的对话框的弹出
- * final PopupWindow pw= new PopupWindow(vPopupWindow,300,300,true);
- *
- *
- *
- * //显示popupWindow对话框
- pw.showAtLocation(parent, Gravity.CENTER, 0, 0);
- * @author longgangbai
- *
- */
- public class AndroidPopupWindowActivity extends Activity {
-
- Button btnPopupWindow;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- //定义按钮
- btnPopupWindow=(Button)this.findViewById(R.id.Button01);
- btnPopupWindow.setOnClickListener(new ClickEvent());
- }
-
-
- //统一处理按键事件
- class ClickEvent implements OnClickListener{
-
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- if(v==btnPopupWindow)
- {
- showPopupWindow(AndroidPopupWindowActivity.this,
- AndroidPopupWindowActivity.this.findViewById(R.id.Button01));
- }
- }
- }
-
- /**
- * 显示相关的PopupWindow对话框
- * @param context
- * @param parent
- */
- public void showPopupWindow(Context context,View parent){
- //获取布局管理对象
- LayoutInflater inflater = (LayoutInflater)
- context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- //获取相关的自定义布局视图
- final View vPopupWindow=inflater.inflate(R.layout.popupwindow, null, false);
- //PopupWindow的对话框的弹出
- final PopupWindow pw= new PopupWindow(vPopupWindow,300,300,true);
-
- //OK按钮及其处理事件
- Button btnOK=(Button)vPopupWindow.findViewById(R.id.BtnOK);
- btnOK.setOnClickListener(new OnClickListener(){
- @Override
- public void onClick(View v) {
- //设置文本框内容
- EditText edtUsername=(EditText)vPopupWindow.findViewById(R.id.username_edit);
- edtUsername.setText("username");
- EditText edtPassword=(EditText)vPopupWindow.findViewById(R.id.password_edit);
- edtPassword.setText("password");
- }
- });
-
- //Cancel按钮及其处理事件
- Button btnCancel=(Button)vPopupWindow.findViewById(R.id.BtnCancel);
- btnCancel.setOnClickListener(new OnClickListener(){
- @Override
- public void onClick(View v) {
- pw.dismiss();//关闭
- }
- });
- //显示popupWindow对话框
- pw.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
-
- }
-
相关阅读:
关于Form窗体的StartPosition 属性如何设置的问题
Oracle的JDBC Url的几种方式
spring boot不同环境读取不同配置
spring的启动过程就是创建ioc容器的过程
spring容器启动过程理解
spring mvc流程理解
@responsebody注解的作用就是让viewresolver不起作用,不返回视图名称而是直接返回的return object
@Controller和@RestController的区别?
项目包名和分层都是按照代码来分的,不是按照业务。包名是:组织名称+代码分层
WebMvcConfigurer
-
原文地址:https://www.cnblogs.com/shihao/p/2323701.html
Copyright © 2020-2023
润新知