基于popupWindow实现悬浮半透明效果

本文实例为大家分享了popupWindow实现悬浮半透明效果的具体代码,供大家参考,具体内容如下

如上图显示弹出一个半透明框

java代码:

//清空数据
  private void ShowPopup() {
    LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    ViewGroup mView = (ViewGroup) mLayoutInflater.inflate(
        R.layout.soft_calendar_popup, null, true);
    final PopupWindow popupWindow = new PopupWindow(mView,
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
    final RadioButton radio1 = (RadioButton) mView
        .findViewById(R.id.radio0);
    final RadioButton radio2 = (RadioButton) mView
        .findViewById(R.id.radio1);
    final RadioButton radio3 = (RadioButton) mView
        .findViewById(R.id.radio2); 

    Button btn1 = (Button) mView.findViewById(R.id.button1);
    btn1.setOnClickListener(new OnClickListener() { 

      @Override
      public void onClick(View v) {
        //确定按钮实现的操作
        popupWindow.dismiss();
      }
    });
    Button btn2 = (Button) mView.findViewById(R.id.button2);
    btn2.setOnClickListener(new OnClickListener() { 

      @Override
      public void onClick(View v) {
        // 取消按钮实现的操作
        popupWindow.dismiss();
      }
    }); 

    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.showAtLocation(findViewById(R.id.RelativeLayout1),
        Gravity.CENTER | Gravity.CENTER, 0, 0);//在屏幕的中间位置显示
    popupWindow.update();
  }

soft_calendar_popup.xml的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="460px"
  android:layout_height="423px"
  android:background="@drawable/soft_calendar_popup_bg"
  android:orientation="vertical" > 

  <TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30px"
    android:gravity="center"
    android:text="提示"
    android:textColor="@android:color/white"
    android:textSize="25dip" /> 

  <RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="100px"
    android:layout_marginRight="100px"
    android:layout_marginTop="30px" > 

    <RadioButton
      android:id="@+id/radio0"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:checked="true"
      android:text="清除当日缓存"
      android:textSize="20dip"
      android:textColor="@android:color/white" /> 

    <RadioButton
      android:id="@+id/radio1"
      android:textSize="20dip"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="清除当月缓存"
      android:textColor="@android:color/white" /> 

    <RadioButton
      android:id="@+id/radio2"
      android:textSize="20dip"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="清除全部缓存"
      android:textColor="@android:color/white" />
  </RadioGroup> 

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dip"
    android:gravity="center_horizontal" > 

    <Button
      android:id="@+id/button1"
      android:layout_width="158px"
      android:layout_height="wrap_content"
      android:layout_marginRight="30dip"
      android:background="@drawable/btn2"
      android:gravity="center"
      android:text="确定"
      android:textColor="@android:color/white" /> 

    <Button
      android:id="@+id/button2"
      android:layout_width="158px"
      android:layout_height="wrap_content"
      android:background="@drawable/btn1"
      android:gravity="center"
      android:text="返回"
      android:textColor="#0072D7" />
  </LinearLayout> 

</LinearLayout> 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Android之用PopupWindow实现弹出菜单的方法详解

    在使用UC-WebBrowser时,你会发现它的弹出菜单跟系统自带的菜单不一样.它实现更多菜单选项的显示和分栏.其实,它的本身是PopupWindow或者是AlertDialog对话框,在里面添加两个GridView控件,一个是菜单标题栏,一个是菜单选项.菜单选项视图的切换可以通过适配器的变换,轻松地实现.点击下载该实例:一.运行截图:           二.实现要点:(1)屏蔽系统弹出的菜单:1.首先创建至少一个系统的菜单选项 复制代码 代码如下: @Override public bool

  • android popwindow实现左侧弹出菜单层及PopupWindow主要方法介绍

    PopupWindow可以实现浮层效果,主要方法有:可以自定义view,通过LayoutInflator方法:可以出现和退出时显示动画:可以指定显示位置等. 为了将PopupWindow的多个功能展现并力求用简单的代码实现,编写了一个点击按钮左侧弹出菜单的功能,实现出现和退出时显示动画效果并点击其他区域时弹出层自动消失,效果图如下: 源码: 1.PopwindowOnLeftActivity.java 复制代码 代码如下: package com.pop.main; import android

  • Android实现底部弹出PopupWindow背景逐渐变暗效果

    在Android开发中,经常需要通过点击某个按钮弹出对话框或者选择框,通过Dialog或者PopupMenu.PopupWindow都能实现. 这里主要介绍后两者:PopupMenu.PopupWindow的实现. 先看两个效果图上边PopupMenu,下边PopupWindow: PopupMenu PopupWindow 一.PopupMenu实现: PopupMenu实现起来比较简单,主要用来实现根据按钮附近弹出的对话框. 首先定义一个menu文件\res\menu\headmenu.xm

  • Android中PopupWindow响应返回键并关闭的2种方法

    PopupWindow 跟我们的 Activity 不一样,因为我们在构造 PW 的时候往往不是继承来的,而是 new 出来的.所以不能使用重写 PW 的 onKeyDown() 之类的方法来截获键盘事件.好在 PW 本身的特性让我们很容易就能做到用返回键来退出,当然我们也可以截获键盘事件,这样就有两种方法了.   方法一: 最简单的方法 在 new 的时候,使用下面的方法: 复制代码 代码如下: popupWindow = new PopupWindow(popupWindow_view, 2

  • android PopupWindow 和 Activity弹出窗口实现方式

    本人小菜一个.目前只见过两种弹出框的实现方式,第一种是最常见的PopupWindow,第二种也就是Activity的方式是前几天才见识过.感觉很霸气哦.没想到,activity也可以做伪窗口. 先贴上最常见的方法,主要讲activity的方法. 一.弹出PopupWindow 复制代码 代码如下: /** * 弹出menu菜单 */ public void menu_press(){ if(!menu_display){ //获取LayoutInflater实例 inflater = (Layo

  • android使用PopupWindow实现页面点击顶部弹出下拉菜单

    实现此功能没有太多的技术难点,主要通过PopupWindow方法,同时更进一步加深了PopupWindow的使用,实现点击弹出一个自定义的view,view里面可以自由设计,比较常用的可以放一个listview. demo中我只是一个点击展示,简单的使用了fade in out的动画效果,也没有精美的图片资源,看着也丑,不过这么短的时间,让你掌握一个很好用的技术,可以自己扩展,不很好么? 废话不说了,直接上代码: MainActivity.java public class MainActivi

  • Android入门之PopupWindow用法实例解析

    本文实例介绍一下PopupWindow对话框.PopupWindow是阻塞对话框,只有在外部线程 或者 PopupWindow本身做退出操作才可以执行.PopupWindow完全依赖Layout做外观,在常见的开发中,PopupWindow应该会与AlertDialog常混用. 先贴出本例中运行的结果图: main.xml的源码如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmln

  • Android Animation实战之屏幕底部弹出PopupWindow

    Android动画的一个实战内容,从屏幕底部滑动弹出PopupWindow. 相信这种效果大家在很多APP上都遇到过,比如需要拍照或者从SD卡选择图片,再比如需要分享某些东西时,大多会采用这么一种效果: 那这种效果如何实现呢? 我们仿写一个这种效果的实例吧: 1)我们首先定义一下,弹出窗口的页面布局组件:take_photo_pop.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout

  • Android编程实现popupwindow弹出后屏幕背景变成半透明效果

    本文实例讲述了Android编程实现popupwindow弹出后屏幕背景变成半透明效果的方法.分享给大家供大家参考,具体如下: android中popupwindow弹出后,屏幕背景变成半透明这个效果很普通.实现的方法也很多.我使用的可能是最简单的一种,就是设置一下getWindows的透明度.不多说上代码 /** * 设置添加屏幕的背景透明度 * @param bgAlpha */ public void backgroundAlpha(float bgAlpha) { WindowManag

  • Android中自定义PopupWindow实现弹出框并带有动画效果

    使用PopupWindow来实现弹出框,并且带有动画效果 首先自定义PopupWindow public class LostPopupWindow extends PopupWindow { public Lost lost; public void onLost(Lost lost){ this.lost = lost; } private View conentView; public View getConentView() { return conentView; } public L

随机推荐