练习使用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实现对话框的更多相关文章

  1. android学习笔记17——对话框(PopupWindow)

    PopupWindow ==> PopupWindow可创建类似对话框的窗口,使用其创建对话框窗口的操作步骤: 1.调用PopupWindow构造器构造PopupWindow对象: 2.调用Po ...

  2. Android 中PopupWindow使用 (转)

    参考学习后遇到问题: 要引用:有好几个,可以用错误提示解决: import android.widget.PopupWindow; import android.widget.Toast; Activ ...

  3. Android 使用 popupWindow实现弹层并操作弹层元素

    需求: 点页面,出现弹层,弹层包含EditText,Button等,点击Button实现提交操作: 最终代码: private PopupWindow popupWindow ; private Ed ...

  4. android学习笔记16——对话框

    android支持丰富的对话框,常用4中对话框: 1.AlertDialog: 2.ProgressDialog:进度对话框,这个对话框只是对进度条的封装 3.DatePickerDialog:日期选 ...

  5. Android:PopupWindow简单弹窗改进版

    Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...

  6. Android 使用PopupWindow实现弹出菜单

    在本文当中,我将会与大家分享一个封装了PopupWindow实现弹出菜单的类,并说明它的实现与使用. 因对界面的需求,android原生的弹出菜单已不能满足我们的需求,自定义菜单成了我们的唯一选择,在 ...

  7. Android的PopupWindow使用android学习之旅(四十三)

    PopupWindow简介 PopupWindow是一个类似dialog的控件,可以接受任何的view作为下拉列表显示. 用法 代码展示 package peng.liu.test; import a ...

  8. Android开发 PopupWindow弹窗调用第三方地图(百度,高德)实现导航功能

    博客描述:后台返回地点的经纬度在地图上进行描点,点击导航弹出PopupWindow进行选择地图操作,如果手机中没有安装地图,提示没有,否则传值调起地图进行导航操作 看一下实现的效果,没图说再多都白搭 ...

  9. Android学习:AlertDialog对话框

    AlertDialog可以生成各种内容的对话框,它生成的对话框包含4个区域:图标区,标题区,内容区,按钮区 <?xml version="1.0" encoding=&quo ...

随机推荐

  1. 不得不说fdm真的好用

    记忆力太差系列 挺好用的软件 下载器FDM真的很好用

  2. Maximum splitting(规律,数论)

    You are given several queries. In the i-th query you are given a single positive integer ni. You are ...

  3. log4j日志+面向切面监控异常

    log4j.xml src/main/resources ----------------------------------------------------------------------- ...

  4. objectARX加载lisp函数、源码的一种方式

    //感谢高飞鸟highflybird版主的思路以及研究. //先声明非公开函数acedEvaluateLisp extern int acedEvaluateLisp(const ACHAR*,str ...

  5. Linux 下 SSH 远程超时解决方案

    Linux 下 SSH 远程超时解决方案 今天突然看到一个问题说是如何解决SSH远程超时的问题. 找了一点资料.用于解决这个需求~ 第一种:OpenSSH 配置文件设置 位于112行的 "C ...

  6. jxl获取excel中的合并的单元格(主要是方法介绍)

    Range[] rangeCells = sheet.getMergedCells();// 返回sheet中合并的单元格数组 for (Range r : rangeCells) {//对数组遍历拿 ...

  7. UItextInput-Protocol

    UItextInput是一个protocol,一般来说,文字处理的控件都要遵守这个协议.如UITextField,UITextView.下面介绍一些文字处理的基本概念. marked text 对于多 ...

  8. 《[MySQL技术内幕:SQL编程》读书笔记

    <[MySQL技术内幕:SQL编程>读书笔记 2019年3月31日23:12:11 严禁转载!!! <MySQL技术内幕:SQL编程>这本书是我比较喜欢的一位国内作者姜承尧, ...

  9. 2016级算法第四次上机-F.AlvinZH的最“长”公共子序列

    940 AlvinZH的最"长"公共子序列 思路 DP,难题. \(dp[i][j]\) :记录A的前i个字符与B的前j个字符变成相同需要的最小操作数. 初始化:dp[i][0] ...

  10. (一)Win消息机制,SDK编程基础

    一,基本概念 SDK:软件开发工具包(缩写:SDK.外语全称:Software Development Kit) API:应用程序接口 WINAPI:Windows平台下的系统调用,包含 window ...