alertdialog自定义弹窗,点击窗体文字弹窗消失


点击条目最右面的图片,弹出alertdialog(自定义的弹窗样式)

先放上自定义弹窗的布局,

[html] view plain copy
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="match_parent"  
  3.     android:padding="20dp"  
  4.     android:layout_height="match_parent">  
  5.   
  6.     <LinearLayout  
  7.         android:paddingLeft="30dp"  
  8.         android:gravity="center_vertical"  
  9.         android:orientation="vertical"  
  10.         android:layout_width="450dp"  
  11.         android:layout_height="wrap_content">  
  12.     <TextView  
  13.         android:padding="15dp"  
  14.         android:textColor="#000"  
  15.         android:textSize="25sp"  
  16.         android:text="怒放"  
  17.         android:id="@+id/pop_name"  
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content" />  
  20.   
  21.     <TextView  
  22.         android:padding="15dp"  
  23.         android:textColor="#000"  
  24.         android:textSize="20sp"  
  25.         android:text="分享"  
  26.         android:id="@+id/pop_fenxiang"  
  27.         android:layout_width="wrap_content"  
  28.         android:layout_height="wrap_content" />  
  29.   
  30.         <TextView  
  31.             android:padding="15dp"  
  32.             android:textColor="#000"  
  33.             android:textSize="20sp"  
  34.             android:text="查看歌手信息"  
  35.             android:id="@+id/pop_chakan"  
  36.             android:layout_width="wrap_content"  
  37.             android:layout_height="wrap_content" />  
  38.     <TextView  
  39.         android:padding="15dp"  
  40.         android:textColor="#000"  
  41.         android:textSize="20sp"  
  42.         android:text="下载"  
  43.         android:id="@+id/pop_download"  
  44.         android:layout_width="wrap_content"  
  45.         android:layout_height="wrap_content" />  
  46.   
  47.     </LinearLayout>  
  48. </LinearLayout>  
在代码中引入上面的布局,并且设置给alertdialog显示,holder.xuanxiang就是这个图片
[html] view plain copy
  1. holder.xuanxiang.setOnClickListener(new View.OnClickListener() {  
  2.             @Override  
  3.             public void onClick(View view) {  
  4.   
  5.                 //自定义的弹窗布局  
  6.                 contentView = View.inflate(context, R.layout.search_popup, null);  
  7.                // Toast.makeText(context, list.get(position).getSongname(), Toast.LENGTH_SHORT).show();  
  8.                 String name = list.get(position).getSongname();//拿到歌曲名字  
  9.   
  10.                 pop_name = contentView.findViewById(R.id.pop_name);  
  11.                 pop_fenxiang = contentView.findViewById(R.id.pop_fenxiang);  
  12.                 pop_download = contentView.findViewById(R.id.pop_download);  
  13.                 pop_chakan = contentView.findViewById(R.id.pop_chakan);  
  14.                 pop_name.setText(name);//设置显示歌曲名字  
  15.                 //xianShiPop();  
  16.   
  17.                 final AlertDialog.Builder builder = new AlertDialog.Builder(context);  
  18.                 builder.setView(contentView);//设置自定义布局样式弹窗  
  19.                 final AlertDialog alertDialog = builder.create();  
  20.   
  21.                 alertDialog.show();  
  22.   
  23.                 pop_fenxiang.setOnClickListener(new View.OnClickListener() {  
  24.                     @Override  
  25.                     public void onClick(View view) {  
  26.                         //弹出窗体消失  
  27.                         alertDialog.dismiss();  
  28.                     }  
  29.                 });  
  30.   
  31.                 pop_download.setOnClickListener(new View.OnClickListener() {  
  32.                     @Override  
  33.                     public void onClick(View view) {  
  34.                        //弹出窗体消失  
  35.                         alertDialog.dismiss();  
  36.                     }  
  37.                 });  
  38.           }  
  39.         }); 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值