android 自定义Dialog背景透明及显示位置设置的方法
来源:互联网 发布:小学生学编程视频教程 编辑:程序博客网 时间:2024/04/25 11:27
代码如下:
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 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 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">< /LinearLayout>
3、颜色color.xml代码
< ?xml version="1.0" encoding="utf-8"?>
< resources>
< color name="transparent">#00000000
< /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 name="android:windowIsFloating">true
< item name="android:windowIsTranslucent">false
< item name="android:windowNoTitle">true
< item name="android:windowBackground">@color/transparent
< item name="android:backgroundDimEnabled">false
< /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();
以上仅作参考,如有问题,请大家及时提出来,一起交流学习!
- android 自定义Dialog背景透明及显示位置设置的方法
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置(转载)
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- Android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- 阿尔萨斯的背叛 ----没人理解的死亡骑士续写传奇
- 黑马程序员_学习日记19_jQuery
- poj 1298 The Hardest Problem Ever
- Mysql学习2
- Java ObjectInputStream与ObjectOutputStream阻塞(block)问题
- android 自定义Dialog背景透明及显示位置设置的方法
- Ext Grid 状态保存
- Android计算地图上两点距离
- C语言实现一个循环移位函数
- Git使用教程之二技巧篇
- 【物联网智能网关-02】获取摄像头数据+显示
- POI示例
- vs2010web项目调试asp.net 网页调试时提示正在等待来自localhost的响应的解决办法
- 将Android项目中的公共部分提取为公共项目(Library Projects)