android中popupwindow的实现,弹出后页面变暗

首先上xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="15dp" >
    
    <TextView
        android:id="@+id/tv_text_book_pop_window_renjiao"
        android:layout_width="100dp"
        android:layout_height="49.5dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="15dp"
        android:text="人教版"
        android:textColor="@color/action_bar_background"
        android:gravity="center"
        android:background="@color/white"/>
    
	<View
	    android:id="@+id/view_text_book_pop_window_line"    
		android:layout_width="100dp"
		android:layout_height="0.5dp"
		android:layout_alignParentRight="true" 
		android:layout_marginRight="15dp"
		android:background="#d0d0d0"
      	android:layout_below="@id/tv_text_book_pop_window_renjiao"/>
	
	<TextView
        android:id="@+id/tv_text_book_pop_window_beishida"
        android:layout_width="100dp"
        android:layout_height="49.5dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="15dp"
        android:text="北师大版"
        android:textColor="#8e8e8e"
        android:gravity="center"
        android:layout_below="@id/view_text_book_pop_window_line"
        android:background="@color/white"/>
	
	<View
		android:layout_width="100dp"
		android:layout_height="0.5dp" 
		android:background="#d0d0d0"
		android:layout_alignParentRight="true"
		android:layout_marginRight="15dp"
      	android:layout_below="@id/tv_text_book_pop_window_beishida"/>

</RelativeLayout>

可以见得,就是简单的relativelayout
下面是程序中的代码
<pre name="code" class="java">//popUpWindow显示,教材版本
	private void showVersionPopWindow(View parent){
	// 一个自定义的布局,作为显示的内容
        View contentView = LayoutInflater.from(context).inflate(R.layout.text_book_pop_window_version, null);
        // 设置按钮的点击事件

        //各种设置
    
        
        versionPopWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, true); 
        // 这个是为了点击“返回Back”也能使其消失,并且并不会影响背景
        versionPopWindow.setBackgroundDrawable(new BitmapDrawable());
        
        versionPopWindow.setTouchable(true);
        // 使其聚集
        versionPopWindow.setFocusable(true);
        // 设置允许在外点击消失
        versionPopWindow.setOutsideTouchable(true);
        // 设置消失的监听
        versionPopWindow.setOnDismissListener(popDismissListener);
        
        //相对的偏移量
        int xPos = 0;
        int yPos = 0;
        
        //设置背景透明
        backgroundTextView.setVisibility(View.VISIBLE);
        //显示popUpWindow
        versionPopWindow.showAsDropDown(parent, xPos, yPos);
	}


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值