[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 ...
随机推荐
- eclipse - maven使用国内镜像
1 使用 maven 插件 - 官网下载 2 修改 eg : apache-maven-3.6.0-bin\apache-maven-3.6.0\conf\ setting.xml - 可备份下 3 ...
- Java反射机制与工厂模式
工厂模式属于创建型模式,它提供了一种创建对象的最佳方式. 它的特点是:客户端的程序类不直接牵扯到对象的实例化管理,只与接口发生关联,通过工厂类获取指定接口的实例化对象. 简单工厂模式如下: inter ...
- css3箭头
<!DOCTYPE html> <html lang="en" class="muui-theme-webapp-main"> < ...
- Ubuntu的中文乱码问题
目标:使系统/服务器支持中文,能够正常显示. 1.首先,安装中文支持包language-pack-zh-hans: $ sudo apt-get install language-pack-zh-ha ...
- jquer 使用原生DOM对象
js中使document.getElementById("ID"); Jquery中可以使用$("#id") 或者$("#id").get( ...
- 除了ROS, 机器人定位导航还有其他方案吗?
利用ROS进行机器人开发,我想大多数企业是想借助ROS实现机器人的导航.定位与路径规划,它的出现大大降低了机器人领域的开发门槛,开发者无需向前人一样走众多弯路,掌握多种知识才能开始实现机器人设计的梦想 ...
- 世界最大BT服务器本周死了三回 海盗湾要凉凉?
想當初,我是受到BT網站海盜灣的啟發,開發了一個DHT下載網站:http://www.ibmid.com,有一段時間通宵編程,理解此個協議. 海盗湾(The Pirate Bay)是世界上最大的 BT ...
- bzoj 3261 最大异或和 可持久化字典树(01树)
题目传送门 思路: 由异或的性质可得,题目要求的式子可以转化成求$max(pre[n]^x^pre[i])$,$pre[i]$表示前缀异或和,那么我们现在就要求出这个东西,所以用可持久化字典树来求,每 ...
- 2019年华南理工大学程序设计竞赛(春季赛)A NB群友
https://ac.nowcoder.com/acm/contest/625/A 题意:给出一个区间范围 , 求有多少个数的每一位的积是在这个区间里面的 分析:没错了 ,就是记忆化暴力搜索 ,不断的 ...
- Codeforces - tag::flows 大合集 [完坑 x14]
589F 题意:给出n个时间区间,每个区间挑定长的非连续区间,求不同个区间不存在时间冲突的最大定长,输出乘上n 二分图模型+二分长度,左顶点集为区间编号,右顶点集为时间编号(1...10000),汇点 ...