android 对话框Dialog背景透明
2011-10-14 20:04
483 查看
先看效果:
![](http://hi.csdn.net/attachment/201110/14/0_1318593220APH7.gif)
![](http://hi.csdn.net/attachment/201110/14/0_1318593249Tq0m.gif)
这是我做的一个拨号器强的面板,拨号的时候会查询手机中的联系人,显示在拨号面板上方,点击弹出透明对话框供选择。
这次重点是透明对话框。
先看对话框的theme,style文件:
对话框背景@drawable/selector_dialog_bg:
然后是对话框的布局:
程序中:
其实主要是通过WindowManager.LayoutParams给对话框设置属性。
![](http://hi.csdn.net/attachment/201110/14/0_1318593220APH7.gif)
![](http://hi.csdn.net/attachment/201110/14/0_1318593249Tq0m.gif)
这是我做的一个拨号器强的面板,拨号的时候会查询手机中的联系人,显示在拨号面板上方,点击弹出透明对话框供选择。
这次重点是透明对话框。
先看对话框的theme,style文件:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="selectorDialog" 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">@drawable/selector_dialog_bg</item><!--背景透明--> <item name="android:backgroundDimEnabled">false</item><!--模糊--> <item name="android:backgroundDimAmount">0.6</item> </style> </resources>
对话框背景@drawable/selector_dialog_bg:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#333333"/> <stroke android:width="2dp" android:color="#99CC33" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> <corners android:radius="8dp" /> </shape>
然后是对话框的布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <ListView android:id="@+id/selector_dialog_listview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:cacheColorHint="#00000000" android:scrollbars="none" android:dividerHeight="1.0dip" android:divider="#C4C4C4" /> </LinearLayout>
程序中:
final View view = LayoutInflater.from(this).inflate(R.layout.selector_dialog, null); selectorDialog = new Dialog(DialerActivity.this, R.style.selectorDialog); selectorDialog.setContentView(view); final BaseAdapter adapter = new SelectorAdapter(DialerActivity.this, selectorList); ListView listView = (ListView) view.findViewById(R.id.selector_dialog_listview); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //对话框中事件处理 } }); listView.setAdapter(adapter); selectorDialog.show(); selectorDialog.setCanceledOnTouchOutside(true); WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); WindowManager.LayoutParams lp = selectorDialog.getWindow().getAttributes(); lp.width = (int)(display.getWidth() * 0.9); if(selectorList.size() > 7) { lp.height = (int)(display.getHeight() * 0.9); } lp.alpha = 0.8f; selectorDialog.getWindow().setAttributes(lp);
其实主要是通过WindowManager.LayoutParams给对话框设置属性。
相关文章推荐
- Android编程实现对话框Dialog背景透明功能示例
- android--对话框Dialog背景透明
- Android 设置dialog背景全透明无边框
- android 设置activity为对话框,且背景为透明
- Android Dialog背景全透明无边框 Theme Style
- Android 设置dialog背景全透明无边框
- Android 4.x上适配设置DialogFragment背景透明--可拓展实现悬浮关闭按钮
- 解决android 5.0 dialog背景无法透明的问题
- 浅谈自定义不规则背景的对话框,透明背景的对话框dialog定义过程中的注意事项
- android 自定义Dialog背景透明及显示位置设置(转载)
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- Android如何创建背景透明的Dialog
- Android Dialog 系统样式讲解及透明背景
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- android 自定义Dialog背景透明及显示位置设置
- Android开发:自定义对话框(自定义布局及背景透明等)
- android 自定义Dialog背景透明及显示位置设置
- Android Dialog背景全透明无边框 Theme Style