Android开发:自定义对话框(自定义布局及背景透明等)
2013-08-21 14:25
489 查看
直接从android.app.Dialog.Dialog类自定义,代码如下:
R.style.UpdateDialog在styles.xml中进行定义,如下:
在配置文件中可设置对话框的多个属性。
final Dialog dialog = new Dialog(MainActivity.this, R.style.UpdateDialog); View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.update_dialog, null); dialog.setContentView(view); Button btn_yes = (Button)view.findViewById(R.id.update_yes); Button btn_no = (Button)view.findViewById(R.id.update_no); btn_yes.setOnClickListener(new OnClickListener(){ public void onClick(View v) { dialog.dismiss(); } }); btn_no.setOnClickListener(new OnClickListener(){ public void onClick(View v) { dialog.dismiss(); } }); dialog.show();
R.style.UpdateDialog在styles.xml中进行定义,如下:
<resources> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> <style name="UpdateDialog" 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/trans</item><!--背景透明--> <item name="android:backgroundDimEnabled">true</item><!--模糊--> <item name="android:backgroundDimAmount">0.0</item> </style> </resources>
在配置文件中可设置对话框的多个属性。
相关文章推荐
- Android自定义全透明Dalog对话框以及自定义全透明Taost弹出框+对话框背景模糊处理
- Android自定义对话框,背景颜色透明
- android 自定义对话框 背景透明
- android 自定义对话框 背景透明
- Android开发——AlertDialog自定义对话框
- Android开发之自定义对话框(2)—加入EditText
- android 自定义Dialog背景透明及显示位置设置
- Android开发:自定义GridView的子项在被选中、获取焦点、按下时的背景
- android开发之自定义对话框
- Android布局之LinearLayout自定义高亮背景的方法
- Android开发实现项目背景布局播放视频
- 【Android开发笔记】 弹出可编辑对话框(布局管理器 LayoutInflater )
- android 自定义Dialog背景透明及显示位置设置
- Android中布局或控件自定义背景
- Android开发之自定义布局和控件
- Android开发中自定义View设定到FrameLayout布局中实现多组件显示
- android自定义透明对话框,透明提示框,自定义Dialog
- Android布局自定义Shap圆形ImageView,可以单独设置背景与图片
- Android 自定义Dialog背景透明及显示位置设置
- Android编程实现对话框Dialog背景透明功能示例