Android自定义对话框的实现
来源:互联网 发布:瑞美单机版网络通信 编辑:程序博客网 时间:2024/05/21 08:51
自定义对话框的思路就是编写对话框的布局文件xml,然后在对话框中显示不同的控件。以下以显示文本控件为例(ImageView等都可以显示)。
1.布局文件connect_dlg.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_height="wrap_content" android:layout_width="fill_parent"android:background="#ffffffff" android:orientation="vertical"android:id="@+id/llToast" ><TextViewandroid:layout_height="wrap_content"android:layout_margin="1dip"android:textColor="#ffffffff"android:layout_width="fill_parent"android:gravity="center"android:textSize="16sp"android:background="#FF129de2"android:id="@+id/tvTitleToast" /><LinearLayoutandroid:layout_height="wrap_content"android:orientation="vertical"android:id="@+id/llToastContent"android:layout_marginLeft="1dip"android:layout_marginRight="1dip"android:layout_marginBottom="1dip"android:layout_width="wrap_content"android:padding="15dip"android:background="#FFFFFFFF" ><TextViewandroid:layout_height="wrap_content"android:paddingRight="10dip"android:paddingLeft="10dip"android:layout_width="wrap_content"android:gravity="center"android:textSize="16sp"android:textColor="#FFff6699"android:id="@+id/tvTextToast" /></LinearLayout><LinearLayout android:id="@+id/MyLayout_ad2" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="40sp"> <com.tencent.exmobwin.banner.TAdView android:id="@+id/adview2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="top|right" > </com.tencent.exmobwin.banner.TAdView> </LinearLayout></LinearLayout>
2.编写显示对话框函数。ShowConnectDialog(String textString)
private void ShowConnectDialog(String textString) {LinearLayout loginLayout1 = (LinearLayout) getLayoutInflater().inflate(R.layout.connect_dlg, null);// adView.TextView title = (TextView) loginLayout1.findViewById(R.id.tvTitleToast);title.setText("系统提示");TextView text1 = (TextView) loginLayout1.findViewById(R.id.tvTextToast);text1.setText(textString);AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setView(loginLayout1);builder.setPositiveButton("下载MobCtrl服务器?", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//处理确定按钮}});builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// 处理取消按钮finish();}});builder.create().show();}
3.显示对话框。在需要显示的地方调用即可。
ShowConnectDialog("连接超时,请检查服务器是否开启及IP地址是否输入正确。确保电脑和手机连接在同一个网络内。");
4.效果
- Android自定义对话框的实现
- 自定义对话框的实现--Android
- Android实现自定义对话框
- 完全自定义Android对话框AlertDialog的实现
- android自定义实现好看的对话框
- android的自定义dialog对话框实现
- 完全自定义Android对话框AlertDialog的实现
- Android系统对话框和自定义对话框实现
- Android自定义Alertdialog对话框实现
- Android 完全自定义对话框的实现(标题栏+EditText+双按钮)
- android 自定义View【2】对话框取色&色盘取色的实现
- Android AlertDialog对话框自定义风格的另类实现
- android使用NumberPicker实现自定义带时间的对话框
- 完全自定义Android对话框AlertDialog的实现(系统源码)
- Builder模式在Android自定义底部对话框的实现
- Android自定义对话框实现以及style的应用
- Android AlertDialog对话框自定义风格的另类实现
- Android底部对话框的实现(BottomSheet,自定义Dialog)
- Android学习笔记:如何使用真机调试应用程序
- Java保存Cookie
- fatal error C1001: INTERNAL COMPILER ERROR(compiler file 'msc1.cpp', line 1786)解决方法
- Java开源 J2EE框架
- POJ 2533 Longest Ordered Subsequence 编程之美 2.16 求数组中最长递增子序列
- Android自定义对话框的实现
- poj2236 并查集
- Qt 与 JS 之间如何交互
- C#中ListView(CheckBox)滚动的技巧
- Android错误:Failed to install *.apk on device *: timeout
- Oracle 10g Shrink Table 详解[表空间收缩]
- USACO Section 1.2 Milking Cows
- 让程序可以脱离opencv,vs等开发环境运
- UVa 10050 - Hartals