安卓弹出框popupwindow及其透明效果小结

Android的对话框有两种:PopupWindow和AlertDialog。它们的不同点在于:

   AlertDialog的位置固定,而PopupWindow的位置可以随意

   AlertDialog是非阻塞线程的,而PopupWindow是阻塞线程

popupwindow 新建步骤:

//弹出框所属XML的ID

  View popupWindow_view = getLayoutInflater().inflate(R.layout.pop, null,
false);
  ContentListView muluListView= (ContentListView) popupWindow_view.findViewById(R.id.zb_listView);

  //显示提供了两种形式

public void showAsDropDown(View anchor, int xoff, int yoff, int gravity)
public void showAtLocation(View parent, int gravity, int x, int y)
 
//注意:没有设置backgroundDrawable的话,弹出的窗口不会消失
popupWindow.setBackgroundDrawable(new BitmapDrawable());
 
如果要设置弹出框的样式可以在android:background="@drawable/xml"中设置背景
 
例如:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#80065e8d"
        />

    <stroke
        android:width="1dp"
        android:color="#363636" />

    <gradient
        android:endColor="#7A7A7A"
        android:startColor="#7A7A7A" />

    <padding
        android:bottom="7dp"
        android:left="7dp"
        android:right="7dp"
        android:top="7dp" />

    <corners android:radius="10dp" />

</shape>


注意
<solid android:color="#80065e8d"
        />可以设置背景半透明
</pre>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值