自定义android dialog
来源:互联网 发布:襄阳樊城区移动云计算 编辑:程序博客网 时间:2024/05/18 02:26
以下例子为使用自定义页面布局来制作自定义dialog,下面分别展示java代码和xml布局代码:
java dialog代码:
public void showTextQuestionDialog(String title, String content, final int position)//dialog方法{
final AlertDialog build = new AlertDialog.Builder(this).create();
build.show();
Window window = build.getWindow();
window.setContentView(R.layout.test_question);//创建对话框使用到的布局页面
build.setCancelable(false);//对话框点击其他位置是否可取消
ImageButton close;
final RadioButton yes;
final RadioButton no;
//所在布局页面的控件
TextView text_question1_content_txt = (TextView) window.findViewById(R.id.text_question1_content_txt);TextView text_question1_title_tv = (TextView) window.findViewById(R.id.text_question1_title_tv);
text_question1_title_tv.setText(title);
text_question1_content_txt.setText(content);
close = (ImageButton) window.findViewById(R.id.text_question_close);
// share = (ImageButton)
// window.findViewById(R.id.text_question1_share_imgbuton);
yes = (RadioButton) window.findViewById(R.id.text_question1_yes);
no = (RadioButton) window.findViewById(R.id.text_question1_no);
布局文件xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_centerInParent="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/text_question_bg" >
<TextView
android:id="@+id/text_question1_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="测试题1"
android:textColor="@android:color/white"
android:textSize="20dp"
android:layout_marginTop="10dp" />
<ImageView
android:id="@+id/text_question1_content_img"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@id/text_question1_title_tv"
android:background="@drawable/text_question1_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:visibility="gone"
android:layout_marginTop="40dp"
/>
<TextView
android:id="@+id/text_question1_content_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/text_question1_title_tv"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="40dp"
/>
<RadioGroup
android:id="@+id/text_question1_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="50dp"
android:layout_marginTop="30dp"
android:layout_below="@id/text_question1_content_txt"
android:orientation="horizontal">
<RadioButton
android:id="@+id/text_question1_yes"
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_weight="1"
android:button="@null"
android:background="@drawable/test_question_radio_yes_style"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="2"/>
<RadioButton
android:id="@+id/text_question1_no"
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_weight="1"
android:button="@null"
android:background="@drawable/test_question_radio_no_style"/>
</RadioGroup>
</RelativeLayout>
<ImageButton
android:id="@+id/text_question_close"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_alignParentRight="true"
android:background="@drawable/text_question_close"
android:layout_marginBottom="30dp" />
</RelativeLayout>
显示页面如下:
- 自定义Dialog android Dialog
- 【Android】Dialog以及自定义Dialog
- android 系统Dialog,自定义Dialog
- android 自定义dialog 自定义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
- ios-vcf格式通讯录的生成和解析(开源),支持5.0以下版本
- ViewPager+Fragment嵌套
- 关于<img>标签无法显示名字中带有中文的图片的问题
- C++中公有继承、保护继承、私有继承的区别
- easyui-datagrid多笔删除的BUG
- 自定义android dialog
- 用到ListActivity中 , @+id/android:list"和"@android:id/list"的写法
- Ubuntu 中文输入法的安装
- Password Managers Attacks and Defenses_论文阅读报告
- 敏捷软件测试--初见
- JS实现 分享视频中-->点击button(copy),复制对应网址
- 数据库查询及随机更新的那些事情
- control your panel
- php面向对象(OOP)—类自动载入的思想历程