PopupWindow菜单实现父窗口遮罩
来源:互联网 发布:淘宝连衣裙店铺推荐 编辑:程序博客网 时间:2024/05/01 16:40
重点内容在注释中体现:全屏显示一个页面,将这个页面背景设置成半透明,菜单控件显示在屏幕下方,即可完成popupwindow菜单,并实现了父窗口遮罩
popupwindow xml文件 login_type_popupwindow.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#b0000000" ><!-全屏灰色半透明-> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignParentBottom="true" android:layout_marginBottom="10dp" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/common_white_bg" android:orientation="vertical" > <TextView android:id="@+id/mServerLogin" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:paddingBottom="8dp" android:paddingTop="8dp" android:text="@string/serverLogin" android:textColor="#3995e1" android:textSize="@dimen/title_text_size" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#999999" /> <TextView android:id="@+id/mSmsLogin" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:paddingBottom="8dp" android:paddingTop="8dp" android:text="@string/messageLogin" android:textColor="#3995e1" android:textSize="@dimen/title_text_size" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="15dp" android:background="@drawable/common_white_bg_select" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:paddingBottom="8dp" android:paddingTop="8dp" android:text="@string/cancel" android:textColor="#3995e1" android:textSize="@dimen/title_text_size" /> </LinearLayout> </LinearLayout></RelativeLayout>
style.xml
<!-- popupwindow 动画 --> <style name="animation"> <item name="android:windowEnterAnimation">@anim/enter</item> <item name="android:windowExitAnimation">@anim/out</item> </style>
enter_anim.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="500" /> <alpha android:fromAlpha="0.7" android:toAlpha="1.0" android:duration="300" /> </set>
out_anim.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="3000" /> <alpha android:fromAlpha="1.0" android:toAlpha="0.5" android:duration="2000" /> </set>
下面是java代码
//初始化方法private void InitPopupWindow() {View contentView = getLayoutInflater().inflate(R.layout.login_type_popwindow, null);//动态加载TextView mServerLogin = (TextView) contentView.findViewById(R.id.mServerLogin);TextView mSmsLogin = (TextView) contentView.findViewById(R.id.mSmsLogin);mServerLogin.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {if (popupWindow.isShowing())popupWindow.dismiss();}});mSmsLogin.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {if (popupWindow.isShowing())popupWindow.dismiss();}});popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);//全屏显示,将内容设置在底部popupWindow.setFocusable(true);popupWindow.setBackgroundDrawable(new BitmapDrawable());popupWindow.setAnimationStyle(R.style.animation);parent = this.findViewById(R.id.activity_login);//父窗口view}
使用方法在oncreate()方法中调用InitPopupWindow();然后再需要弹出popupwindow的空间点击时间中调用popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);即可!
1 0
- PopupWindow菜单实现父窗口遮罩
- android中使用PopupWindow实现弹出窗口菜单
- android 下拉窗口菜单的实现(popupwindow)
- Popupwindow实现下拉菜单
- popupWindow 实现菜单
- PopupWindow实现弹出窗口
- popupwindow 如何实现弹出菜单效果_popupwindow 实现弹出窗口范例
- 用PopupWindow实现下拉菜单
- PopupWindow实现弹出菜单效果
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 点击按钮改变input text的value值
- js获取<a>标签中的值
- win7 VS2008 X64 pcomm串口控制开发方法
- 2013年05月02日
- (转)iscroll4的用法
- PopupWindow菜单实现父窗口遮罩
- (转)html鼠标事件
- 黑马程序员 数组的使用
- phonegap 长按列表弹出对话框
- 利用HTML5实现页面预加载
- 新年寄望:从小做起,活在当下
- HTML5制作Loading加载效果
- (转)html5各种页面切换效果和模态…
- 24种HTML页面切换效果(转)