android 自定义Dialog背景透明及显示位置设置

android 自定义Dialog背景透明及显示位置设置

Posted on 2011-09-14 21:35 linFen 阅读( 5213) 评论( 9) 编辑 收藏

 

代码如下:

 

1、自定义Dialog

 

复制代码
public  class SelectDialog extends AlertDialog{

public SelectDialog(Context context,  int theme) {
    super(context, theme);
}

public SelectDialog(Context context) {
    super(context);
}

@Override
protected  void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.slt_cnt_type);
}
}
复制代码

 

 

2、布局文件slt_cnt_type.xml代码 

 

复制代码
<?xml version= " 1.0 " encoding= " utf-8 "?>
<LinearLayout
  xmlns:android= " http://schemas.android.com/apk/res/android "
  android:orientation= " vertical "
  android:padding= " 10dp " android:layout_width= " 115dp " android:layout_height= " wrap_content " android:background= " @color/blue ">
    <Button android:layout_height= " wrap_content " android:background= " #00000000 " android:layout_width= " fill_parent " android:text= " 全部联系人 " android:paddingTop= " 5dp " android:paddingBottom= " 5dp " android:paddingLeft= " 10dp " android:gravity= " left|center_vertical " android:id= " @+id/btnSltCntAll "></Button>
    <Button android:layout_height= " wrap_content " android:background= " #00000000 " style= " @drawable/greenhand_button " android:text= " 咕咚用户 " android:gravity= " left|center_vertical " android:paddingBottom= " 5dp " android:paddingTop= " 5dp " android:paddingLeft= " 10dp " android:paddingRight= " 10dp " android:layout_width= " fill_parent " android:id= " @+id/btnSltGudongUser "></Button>
    <Button style= " @drawable/greenhand_button " android:background= " #00000000 " android:layout_height= " wrap_content " android:layout_width= " fill_parent " android:text= " 推荐用户 " android:gravity= " left|center_vertical " android:paddingTop= " 5dp " android:paddingBottom= " 5dp " android:paddingLeft= " 10dp " android:id= " @+id/btnSltRecommend "></Button>
</LinearLayout>
复制代码

 

3、颜色color.xml代码

 

<?xml version= " 1.0 " encoding= " utf-8 "?>
<resources>
  <color name= " transparent "># 00000000</color>
</resources>

 

4、样式style.xml代码

 

复制代码
<?xml version= " 1.0 " encoding= " utf-8 "?>
<resources>
    <style name= " dialog " parent= " @android:style/Theme.Dialog ">
        <item name= " android:windowFrame ">@null</item><!--边框-->
        <item name= " android:windowIsFloating "> true</item><!--是否浮现在activity之上-->
        <item name= " android:windowIsTranslucent "> false</item><!--半透明-->
        <item name= " android:windowNoTitle "> true</item><!--无标题-->
        <item name= " android:windowBackground ">@color/transparent</item><!--背景透明-->
        <item name= " android:backgroundDimEnabled "> false</item><!--模糊-->
    </style>
</resources>
复制代码

 

 

4、显示Dialog

 

复制代码
SelectDialog selectDialog =  new SelectDialog( this,R.style.dialog);//创建Dialog并设置样式主题
Window win = selectDialog.getWindow();
LayoutParams params =  new LayoutParams();
params.x = -80;//设置x坐标
params.y = -60;//设置y坐标
win.setAttributes(params);
selectDialog.setCanceledOnTouchOutside( true);//设置点击Dialog外部任意区域关闭Dialog
selectDialog.show();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值