先贴一下显示效果图,仅作参考:

 

android 自定义Dialog背景透明及显示位置设置_第1张图片

 

代码如下:

 

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 >
        
< 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();

更多相关文章

  1. Android 不通过parent实现样式继承
  2. apk安装法之二----一段Android实现应用下载并自动安装apk包的代
  3. Android 通知的基本用法示例代码
  4. Android使用代码实现RelativeLayout,LinearLayout布局
  5. Android 从代码中打开淘宝和亚马逊、facebook、Message
  6. 修改dialog背景以及代码扩展AlertDialog和tint的使用
  7. 【Android】Android 彩信发送的两种方式+源代码
  8. Android发送短信功能代码
  9. [置顶] Android源代码下载

随机推荐

  1. android camera 源码分析(基于应用)
  2. 【Android】状态栏通知Notification、Not
  3. andio:android 音频的代码层次关系
  4. Android(安卓)的 SDK Manager 无法启动
  5. android 程序开发的插件化 模块化方法 之
  6. Android(安卓)恢复出厂设置(recovery)
  7. Android(安卓)ClassLoader解析(2) - Andr
  8. Android(安卓)cupcake源代码获取和编译 f
  9. 学习笔记:原生(android,ios)使用阿里iconf
  10. android web services7