20150604_Andriod 窗体PopupWindow
package com.example.test1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
////////////////////////////
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
//import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
//import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Toast;
////////////////////////////
public class PopupWindow2 extends ActionBarActivity {
////////////////////////////
private Button button;
private Button button1;
private Button button2;
private Button button3;
private Button button4;
private View popupWindowView;
private PopupWindow popupWindow;
private LayoutInflater inflater;
////////////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popup_window2);
////////////////////////////
button=(Button) findViewById(R.id.button_m);
button.setOnClickListener(new ButtonOnClickListener());
////////////////////////////
}
////////////////////////////
private class ButtonOnClickListener implements OnClickListener{
public void onClick(View v) {
inflater=(LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
popupWindowView=inflater.inflate(R.layout.activity_popup_window_sub, null);
popupWindow=new PopupWindow(popupWindowView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,true);
//必须要有这句否则弹出popupWindow后监听不到Back键
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAtLocation(findViewById(R.id.button_m), Gravity.NO_GRAVITY, 0, 0);
//让popupWindow获得焦点
popupWindow.setFocusable(true);
//设置动画
//popupWindow.setAnimationStyle(R.style.popupWindowAnimation);
popupWindow.update();
//popupWindow中按钮的处理
button1=(Button) popupWindowView.findViewById(R.id.button1);
button2=(Button) popupWindowView.findViewById(R.id.button2);
button3=(Button) popupWindowView.findViewById(R.id.button3);
button4=(Button) popupWindowView.findViewById(R.id.button4);
button1.setOnClickListener(new ButtonsOnClickListener());
button2.setOnClickListener(new ButtonsOnClickListener());
button3.setOnClickListener(new ButtonsOnClickListener());
button4.setOnClickListener(new ButtonsOnClickListener());
}
}
private class ButtonsOnClickListener implements OnClickListener {
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
//System.out.println("点击了按钮1");
Toast.makeText(getApplicationContext(), "提示:点击了按钮1,点击窗口外部关闭窗口!",
Toast.LENGTH_SHORT).show();
break;
case R.id.button2:
System.out.println("点击了按钮2");
break;
case R.id.button3:
System.out.println("点击了按钮3");
break;
case R.id.button4:
//System.out.println("点击了按钮4");
popupWindow.dismiss(); // 关闭窗口
break;
default:
break;
}
}
}
//监听Back事件
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode==KeyEvent.KEYCODE_BACK) {
if (popupWindow!=null&&popupWindow.isShowing()) {
popupWindow.dismiss();
} else {
//MainActivity.this.finish();
PopupWindow2.this.finish();
}
}
return super.onKeyDown(keyCode, event);
}
////////////////////////////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.popup_window2, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
//////////////////////////////////////////////////////////////
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test1.PopupWindow2" >
<Button
android:id="@+id/button_m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="test" />
</RelativeLayout>
//////////////////////////////////////////////////////////////
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test1.PopupWindow_sub" >
<LinearLayout
android:id="@+id/linerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Button1"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
<Button
android:id="@+id/button2"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Button2"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
<Button
android:id="@+id/button3"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Button3"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
<Button
android:id="@+id/button4"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Button4"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
</LinearLayout>
</RelativeLayout>
//////////////////////////////////////////////////////////////
20150604_Andriod 窗体PopupWindow的更多相关文章
- 20150604_Andriod 窗体PopupWindow动画
参考地址: http://www.open-open.com/lib/view/open1378720752084.html http://www.jcodecraeer.com/a/anzhuoka ...
- Android popupwindow 失去焦点或者点击空白区域时消失的解决方法
先来看下Android API 的这个Methods: public void setOutsideTouchable (boolean touchable) Controls whether the ...
- popUpWindow 动画无法超出窗体的解决方案
popupWindow 做动画时,当要求有一个放大动画时,动画无法超出窗体,给人的感觉是只有内容在放大,窗体不动. 这是由于窗口大小固定的原因,解决方案是加大popUpwindow的 大小. 一个比较 ...
- PopupWindow 防微信弹出右 侧窗体(继承PopupWindow )
1, pop自定义 public class SelectPicPopupWindow extends PopupWindow { private Button btn_take_photo, btn ...
- PopupWindow 从底部弹出窗体
第一步 : 初始化PopupWindow private void initPop() { if (view == null) { // 照片 view = View.inflate(Registe ...
- PopupWindow --- 弹出底部窗体
第一步 : 布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...
- 仿QQ空间根据位置弹出PopupWindow显示更多操作效果
我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: ...
- popupwindow的基本使用以及基本动画效果
1.创建一个popupwindow view的布局文件自己写一个就好了,这里就不说了 View view= LayoutInflater.from(context).inflate(R.layout. ...
- webview加载h5,关闭activity时,窗体泄露问题
问题描述: webview加载一个含有input控件的html页面,当点击input控件是回调app的closepage方法[closepage中只有一个finish操作],出现窗体泄露问题. 分析: ...
随机推荐
- Java基础之访问文件与目录——列出目录内容(ListDirectoryContents)
控制台程序,列出目录的全部内容并使用过滤器来选择特定的条目. import java.nio.file.*; import java.io.IOException; public class List ...
- PostgreSQL:安装
官网地址:https://www.postgresql.org/ 安装文件下载地址:http://www.enterprisedb.com/products-services-training/pgd ...
- php 随机生成
php随机生成6位字符串: $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $max = ...
- bzoj3437 小P的牧场
斜率优化dp 代码 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll ...
- c#经典俄罗斯方块 vs2012开发
把网上两个开源的俄罗斯方块,整合到一起了,开发环境vs2012+.net 4.0,有问题.建议可以加群沟通哦 复古的 c#写的一个俄罗斯方块小游戏,友好的人机交互,具体功能如下: 1.游戏分七个关卡, ...
- paper 61:计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接
转载出处:blog.csdn.net/carson2005 以下链接是本人整理的关于计算机视觉(ComputerVision, CV)相关领域的网站链接,其中有CV牛人的主页,CV研究小组的主页,CV ...
- DataTable 筛选数据
//使用聚合函数 max ,sum ,count .... private void ComputeBySalesSalesID(DataSet dataSet) { // Presumes ...
- MYSQL日期类型的加减更新使用INTERVAL 1 DAY
例如:UPDATE teachingplan SET teachPlanBeginTime = teachPlanBeginTime +INTERVAL 1 DAY
- crontab 误区
# For details see man 4 crontabs# Example of job definition:# .---------------- minute (0 - 59)# | . ...
- 有趣的insert死锁
昨天看到一个很有意思的死锁,拿来记录下: 环境:deadlock on 事务隔离级别: read commited 表结构: root::>show create table lingluo\G ...