展会信息港展会大全

popupwindow的使用
来源:互联网   发布日期:2016-01-14 12:11:59   浏览:2191次  

导读:public class PopUpActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LayoutInflater i...

public class PopUpActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

LayoutInflater inflater = LayoutInflater.from(this);

// 引入窗口配置文件

View view = inflater.inflate(R.layout.main2, null);

// 创建PopupWindow对象

final PopupWindow pop = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, false);

Button btn = (Button) findViewById(R.id.btn);

// 需要设置一下此参数,点击外边可消失

pop.setBackgroundDrawable(new BitmapDrawable());

//设置点击窗口外边窗口消失

pop.setOutsideTouchable(true);

// 设置此参数获得焦点,否则无法点击

pop.setFocusable(true);

btn.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

if(pop.isShowing()) {

// 隐藏窗口,如果设置了点击窗口外小时即不需要此方式隐藏

pop.dismiss();

} else {

// 显示窗口

pop.showAsDropDown(v);

}

}

});

}

}

赞助本站

人工智能实验室

相关热词: android开发 android教程

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港