Android弹出自定义对话框
2012-08-07 11:32
302 查看
1.建立需要弹出的对话框的布局
布局中一共有三个控件,分别为:CheckBox、RatingBar、Button。布局文件为dialog.xml,具体代码如下:
效果图:
![](http://my.csdn.net/uploads/201208/07/1344310707_2013.png)
2.弹出对话框
弹出对话框的主要代码如下:
效果图:
![](http://my.csdn.net/uploads/201208/07/1344310990_7570.png)
来源: http://www.lrguan.com/articles/20130709-01.htm
布局中一共有三个控件,分别为:CheckBox、RatingBar、Button。布局文件为dialog.xml,具体代码如下:
<?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="match_parent" android:orientation="vertical" > <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CheckBox" /> <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout>
效果图:
![](http://my.csdn.net/uploads/201208/07/1344310707_2013.png)
2.弹出对话框
弹出对话框的主要代码如下:
private void showDialog(){ view=this.getLayoutInflater().inflate(R.layout.dialog, null); dialog=new Dialog(this); dialog.setTitle("测试"); dialog.setContentView(view); btn=(Button)view.findViewById(R.id.button2); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub dialog.dismiss(); } }); dialog.show(); }
效果图:
![](http://my.csdn.net/uploads/201208/07/1344310990_7570.png)
来源: http://www.lrguan.com/articles/20130709-01.htm
相关文章推荐
- Android 自定义弹出菜单和对话框功能实例代码
- android中自定义的对话框中的EditText无法弹出输入法解决方案
- android自定义AlertDialog对话框中的EditText无法弹出输入法解决方案
- Android 自定义弹出对话框显示不全的问题
- Android 自定义弹出对话框实例
- android自定义底部弹出对话框
- 21种ANDROID自定义DIALOG_动画弹出对话框效果组件
- Android中Dialog实现自定义弹出对话框
- android 自定义ListView 实现 弹出自定义对话框(带EditText)实现 配置文件实现
- android自定义对话框和弹出框
- android 弹出对话框 弹出自定义对话框
- Android自定义全透明Dalog对话框以及自定义全透明Taost弹出框+对话框背景模糊处理
- Android 自定义弹出菜单和对话框
- android中自定义的对话框中的EditText无法弹出输入法解决方案
- Android 对话框弹出位置和透明度的设置
- Android自定义对话框仿QQ退出
- Androidの自定义对话框AlertDialog(二)
- 在Eclipse RCP Workbench 启动前弹出自定义对话框
- Android:实体按键响应与弹出对话框综合
- Android中自定义的加载对话框和加载条