[android] 练习PopupWindow实现对话框
练习使用Dialog实习对话框
package com.example.tsh; import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow; public class MainActivity extends Activity {
private Handler handler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Dialog实现对话框
Dialog dialog=new Dialog(this,R.style.Theme_Tsh_Dialog);
dialog.setContentView(R.layout.activity_two);
dialog.show(); }
}
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 自定义对话框主题 -->
<style name="Theme.Tsh.Dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@null</item>
</style>
</resources>
练习使用PopupWindow实现对话框
package com.example.tsh; import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow; public class MainActivity extends Activity {
private Handler handler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Dialog实现对话框
// Dialog dialog=new Dialog(this,R.style.Theme_Tsh_Dialog);
// dialog.setContentView(R.layout.activity_two);
// dialog.show(); //使用PopupWindow实现对话框
Button dropDown=(Button) findViewById(R.id.bt_dropdown);
dropDown.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
View anchor=View.inflate(MainActivity.this, R.layout.activity_two, null);
final PopupWindow popupWindow=new PopupWindow(anchor, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true); //点击空白隐藏
popupWindow.setTouchable(true);
popupWindow.setTouchInterceptor(new OnTouchListener() { @Override
public boolean onTouch(View arg0, MotionEvent arg1) {
popupWindow.dismiss();
return false;
}
});
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher));
popupWindow.showAsDropDown(arg0); }
}); }
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="第一个界面"/>
<Button
android:id="@+id/bt_dropdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示下拉"
/>
</LinearLayout>
[android] 练习PopupWindow实现对话框的更多相关文章
- android学习笔记17——对话框(PopupWindow)
PopupWindow ==> PopupWindow可创建类似对话框的窗口,使用其创建对话框窗口的操作步骤: 1.调用PopupWindow构造器构造PopupWindow对象: 2.调用Po ...
- Android 中PopupWindow使用 (转)
参考学习后遇到问题: 要引用:有好几个,可以用错误提示解决: import android.widget.PopupWindow; import android.widget.Toast; Activ ...
- Android 使用 popupWindow实现弹层并操作弹层元素
需求: 点页面,出现弹层,弹层包含EditText,Button等,点击Button实现提交操作: 最终代码: private PopupWindow popupWindow ; private Ed ...
- android学习笔记16——对话框
android支持丰富的对话框,常用4中对话框: 1.AlertDialog: 2.ProgressDialog:进度对话框,这个对话框只是对进度条的封装 3.DatePickerDialog:日期选 ...
- Android:PopupWindow简单弹窗改进版
Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...
- Android 使用PopupWindow实现弹出菜单
在本文当中,我将会与大家分享一个封装了PopupWindow实现弹出菜单的类,并说明它的实现与使用. 因对界面的需求,android原生的弹出菜单已不能满足我们的需求,自定义菜单成了我们的唯一选择,在 ...
- Android的PopupWindow使用android学习之旅(四十三)
PopupWindow简介 PopupWindow是一个类似dialog的控件,可以接受任何的view作为下拉列表显示. 用法 代码展示 package peng.liu.test; import a ...
- Android开发 PopupWindow弹窗调用第三方地图(百度,高德)实现导航功能
博客描述:后台返回地点的经纬度在地图上进行描点,点击导航弹出PopupWindow进行选择地图操作,如果手机中没有安装地图,提示没有,否则传值调起地图进行导航操作 看一下实现的效果,没图说再多都白搭 ...
- Android学习:AlertDialog对话框
AlertDialog可以生成各种内容的对话框,它生成的对话框包含4个区域:图标区,标题区,内容区,按钮区 <?xml version="1.0" encoding=&quo ...
随机推荐
- python IDE安装-mac
mac 配置Python集成开发环境(Eclipse +Python+Pydev) 1.下载Mac版64位的Eclipse. 进入到Eclipse官方网站的下载页面(http://www.ecli ...
- POJ - 2031C - Building a Space Station最小生成树
You are a member of the space station engineering team, and are assigned a task in the construction ...
- Docker容器基础认知
## 一. [docker](http://www.itxdm.me/archives/tag/docker/)概念 [Docker](http://www.itxdm.me/wp-content/p ...
- WordPress翻译更新失败解决方法
编辑php的配置文件:php.ini,搜索并找到disable_functions: 删除disable_functions后面的scandir字符串,保存php.ini: 重载或重启php-fpm服 ...
- easyui页面上显示和PL/SQL编码问题
在页面上,只需要显示人们看的懂的文字就行,但是在数据库里面就不一定了,一般情况下,在数据库里面存字母,数字等除了汉字以外的字符,存汉字有个问题,就是有时候不同oracle数据库的客户端会出现乱码问题: ...
- springboot 搭建 简单 web项目 【springboot + freemark模板 + yml 配置文件 + 热修复 + 测试用例】附源码
项目 地址: https://gitee.com/sanmubird/springboot-simpleweb.git 项目介绍: 本项目主要有一下内容: 1: springboot yml 配置 ...
- JavaScript DOM编程艺术 笔记(一)
探测浏览器品牌版本代码-----浏览器嗅探 代码 JavaScript==ECMAScript java几乎可以部署在任何环境,js只应用于web浏览器 API是一组得到各方面共同认同的基本约定(元素 ...
- weex 编译vue成js
cd 项目 1.开发 npm run web 开发过程中可以直接使用浏览器运行 npm run ios 2.打包 npm run build 会在 dist 文件夹 中生成js文件, 即可拖入ios ...
- tomcat在bin下的startup.bat下启动报错
测试环境是否安装配置好. 如果环境配置好.报错如下:或者是730013 -----------解决问题:是因为tomcat端口被占用.查看是否启动两个tomcat
- 233 Matrix(矩阵快速幂+思维)
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...