• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
百分百
http://www.qrw100.com
博客园    首页    新随笔    联系   管理    订阅  订阅

android 自定义弹出框Dialog(背景图等)

通常在一些应用中,我们需要自定义弹出框,android系统自带的弹出框色彩方面 比较单一。下面介绍一下如何能过xml的布局自定义dialog,很简单的实例: 代码如下: 1. mya_dialog.xml ? xml version = 1.0 encoding = utf-8 ? LinearLayout xmlns:android = htt通常在一些应用中,我们需要自定义弹出框,android系统自带的弹出框色彩方面 比较单一。下面介绍一下如何能过xml的布局自定义dialog,很简单的实例:
代码如下:
1. mya_dialog.xml

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     xmlns:app="http://schemas.android.com/apk/res/com.android.gif" 
  4.     android:orientation="vertical" 
  5.     android:layout_width="220px" 
  6.     android:layout_height="176px" 
  7.     android:background="@drawable/dailog_back" 
  8.     android:id="@+id/layout_root" 
  9.     > 
  10.     <ImageView 
  11.         android:layout_width="wrap_content" 
  12.         android:layout_height="wrap_content" 
  13.         android:src="@drawable/icon" 
  14.         android:layout_marginLeft="10px" 
  15.     /> 
  16.     <TextView 
  17.            android:layout_width="wrap_content" 
  18.         android:layout_height="wrap_content" 
  19.         android:text="loading......" 
  20.         android:gravity="center" 
  21.     /> 
  22. </LinearLayout>
  23. 2.在activity中
     
    1.  AlertDialog myDialog = new AlertDialog.Builder(this).create(); 
    2.  myDialog.show(); 
    3. //这里注意一定要先show dialog 再去加载 contentView。否则会出现异常。 
    4. questFeature must be called before add content) 
    5. myDialog.getWindow().setContentView(R.layout.main);
posted @ 2011-11-04 15:42  爱尚美  阅读(2330)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3