[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 ...
随机推荐
- gulp 图片、样式、js、实时刷新等压缩gulpfile.js文件各个模块
1.压缩tinypng图片 gulp-tinypng-nokey,但不压缩gif格式(另外一个gulp-imagemin压缩率不高,可以压缩gif格式) // 获取 gulp var gulp = ...
- [AIR] AS3读取本地文件夹中的文件
import flash.filesystem.File; import flash.net.URLLoader; //var dir:File = File.desktopDirectory; // ...
- springmvc初步配置
导包/添加依赖: <dependency> <groupId>org.springframework</groupId> <artifactId>spr ...
- 解决mysql最大允许传输包不足的问题
一.报错提示内容和原因 在执行“数据传输”或者“运行SQL文件”时报错误:Got a packet bigger than 'max_allowed_packet' bytes With,表明当前所传 ...
- 2016级算法第三次上机-G.Winter is coming
904 Winter is coming 思路 难题.首先简化问题, \(n\) 个0与 \(m\) 个1排成一列,连续的0不能超过x个,连续的1不能超过y个,求排列方法数. 显然会想到这是动态规划. ...
- python lambda匿名函数 用法
语法 lambda argument_list: expression argument_list是参数列表 expression是一个关于参数的表达式.表达式中出现的参数需要在argument_li ...
- DedeCMS实现自定义表单提交后发送指定QQ邮箱的方法
如月cruyue在做DedeCMS自定义表单发送邮箱的教程,发现大部分都是在php文件里写死固定字段内容,这样虽然也能实现自定义表单提交后发送指定邮箱,但是很不智能,如月cruyue想要一个我们自定义 ...
- C# 获取类名
1.获取C#类中类名 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; 2.获取C#类中类名(包含命名空间) Sy ...
- 《大数据日知录》读书笔记-ch16机器学习:分布式算法
计算广告:逻辑回归 千次展示收益eCPM(Effective Cost Per Mille) eCPM= CTR * BidPrice 优化算法 训练数据使用:在线学习(online learning ...
- oracle--dump & V$BH
一,什么是BH BH即Buffer Header,每一个数据块在被读入buffer cache时,都会先在buffer cache中构造一个buffer header,buffer header与数据 ...