自定义对话框
2015-10-02 00:15
459 查看
1、效果图
2、布局文件
主布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/bt_show" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我" android:layout_centerInParent="true" /> </RelativeLayout>
对话框布局
<?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" > <TextView android:layout_width="match_parent" android:layout_height="50dp" android:background="@drawable/blue_bkg" android:gravity="center" android:text="添加黑名单" android:textColor="#ffffff" android:textSize="26sp" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入黑名单号码" android:inputType="phone" android:textColor="#000000" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <CheckBox android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="#000000" android:text="短信拦截" /> <CheckBox android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="#000000" android:text="电话拦截" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:layout_width="0dip" android:layout_height="40dip" android:layout_weight="1" android:background="@drawable/blue_bkg" android:text="添加" /> <Button android:layout_width="0dip" android:layout_height="40dip" android:layout_weight="1" android:background="@drawable/blue_bkg" android:text="取消" /> </LinearLayout> </LinearLayout>
3、Activity
public class MainActivity extends Activity { private Button bt_show; private AlertDialog mAlertDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initView(); initEvent(); } /** * 初始化按钮点击事件 */ private void initEvent() { bt_show.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mAlertDialog.show(); } }); } /** * 初始化界面、控件 */ private void initView() { setContentView(R.layout.activity_main); bt_show = (Button) findViewById(R.id.bt_show); // 通过对话框添加黑名单数据 AlertDialog.Builder ab = new AlertDialog.Builder(this); // 自定义view View mDialogView = View.inflate(getApplicationContext(), R.layout.dialog, null); //设置界面 ab.setView(mDialogView); mAlertDialog = ab.create(); } }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories