时间来不及,就贴代码了,另外顺便贴一下Activity模拟成一个Dialog,具体可以参考下面的网址

part1 http://blog.stylingandroid.com/archives/5

part2 http://blog.stylingandroid.com/archives/7

part3 http://blog.stylingandroid.com/archives/category/dialog-box

接下来是一个自定义对话框

第一步:

res/values/styles.xml

<?xml version="1.0" encoding="utf-8"?> <resources> <style name="base"> <item name="android:padding">10dp</item> </style> <style name="title" parent="@style/base"> <item name="android:textColor">#FFFFFF</item> <item name="android:textSize">16sp</item> <item name="android:textStyle">bold</item> <item name="android:background">#333333</item> </style> <style name="body" parent="@style/base"> <item name="android:textColor">#FFFFFF</item> <item name="android:background">#666666</item> </style> <style name="dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowIsFloating">true</item> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@null</item> </style> </resources>

第二步:

res/layout/customer_dialog.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"> <TextView android:layout_width="match_parent" android:id="@+id/title" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_height="wrap_content" style="@+style/title" android:text="自定义对话框" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_alignLeft="@id/title" android:layout_below="@id/title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingRight="10dip" android:paddingLeft="10dip" android:id="@+id/body" style="@+style/body" mce_style="@+style/body"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18dip" android:text="用户名:" android:paddingRight="10dip" /> <EditText android:id="@+id/username" android:text="输入用户名" android:layout_width="fill_parent" android:layout_height="wrap_content" android:lines="1" /> </LinearLayout> </RelativeLayout>

第三步:

res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="显示自定义对话框" /> </LinearLayout>

第四步:

src/com/dialog/ui/CustomerDialog.java

package com.dialog.ui; import android.app.AlertDialog; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import com.dialog.activity.R; public class CustomerDialog extends AlertDialog { public CustomerDialog(Context context) { super(context); } public CustomerDialog(Context context, int theme) { super(context, theme); } @Override protected void onCreate(Bundle savedInstanceState) { //关于LayoutInflate详解 //http://blog.csdn.net/jamesliulyc/archive/2011/04/14/6324432.aspx LayoutInflater inflater = LayoutInflater.from(getContext()); View customerLayout = inflater.inflate(R.layout.customer_dialog, null); setView(customerLayout,0,0,0,0); super.onCreate(savedInstanceState); } }

第五步:

src/com/dialog/activity/CustomerDialogActivity.java

package com.dialog.activity; import android.app.Activity; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; import com.dialog.ui.CustomerDialog; public class CustomerDialogActivity extends Activity { private final int CUSTOMER_DIALOG = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.button); View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { showDialog(CUSTOMER_DIALOG); } }; button.setOnClickListener(listener); } @Override protected Dialog onCreateDialog(int id) { CustomerDialog dialog = null; switch(id) { case CUSTOMER_DIALOG: dialog = new CustomerDialog(CustomerDialogActivity.this,R.style.dialog); DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(CustomerDialogActivity.this, "这是一个自定义对话框", Toast.LENGTH_LONG).show(); } }; dialog.setButton("确定", listener); dialog.setButton2("取消", listener); break; } return dialog; } }

效果图:

更多相关文章

  1. Android启动器(Launcher)开发详解
  2. 详解Android(安卓)Handler的使用
  3. Android(安卓)ProGuard 混淆 详解
  4. Android(安卓)View事件派发机制详解与源码分析
  5. Android的Dialog开发和运用
  6. Android使用代码实现左右半圆的按钮背景
  7. Android(安卓)四种加载方式详解(standard singleTop singleTask .
  8. Android(安卓)Back键点击两次退出应用详解及实现方法总结
  9. android-boostrap

随机推荐

  1. 如何在动态生成的表行jquery中添加和操作
  2. 我想在html文件里插入一个for循环,应该如
  3. 如何在localStorage中存储数组?(复制)
  4. 我无法在某些Web浏览器中输入我的注册文
  5. html 引用文件编码为utf-8 的 js文件乱码
  6. 对于MVC中的循环不适用于不同的MapRoute
  7. 当给出%宽度时,表的主体减少了Head的col 1
  8. 关于清除浮动的问题。一招解决
  9. html 加上readonly后在各种浏览器的差异
  10. jQuery onclick不工作在移动设备上