先直接给出效果图:

Android —— 模拟Iphone 样式的 AlertDialog     Android —— 模拟Iphone 样式的 AlertDialog

 

思路:

通过Dialog的方式实现AlertDialog, 因为可以在Dialog中通过setContentView(int layoutResID)来指定Dialog的布局及样式(就像Activity中一样)。

所以我们可以自定义各种样式的alertdialog,至于好不好看,那就得看layout写得怎么样了。

其他也没啥好说的,直接上代码:

java代码:

// write your code to do things after users clicks OK
lDialog.dismiss();
}
});
lDialog.show();

}


}
这代码很短,主要的就是showCustomMessage、showCustomMessageOK这两个显示我们自定义的Alertdialog的方法,关键的就是看怎么编写r_okcanceldialogview.xml和r_okdialogview.xml 这两个layout文件了,下面就给出这两个布局文件的代码:
r_okcanceldialogview.xml :
>
 
r_okdialogview.xml :
>

这两个layout的xml中引用到了一些图片:

android:background="@drawable/alert”

及按钮样式:

android:background="@drawable/custom_button1"

android:background="@drawable/custom_button"
 因为也不多所以也在这里直接贴出来:
alert.png:
Android —— 模拟Iphone 样式的 AlertDialog

custom_button1.xml :

>

custom_button.xml :

>

上面来那个按钮样式中用到的两张图片为:
nofocused.png :
Android —— 模拟Iphone 样式的 AlertDialog

focused.png :

Android —— 模拟Iphone 样式的 AlertDialog

就这么多了,为了方便有需要的人,这里直接给出源码的下载地址:

http://download.csdn.net/source/3480914

相关文章:

  • 2021-09-20
  • 2021-06-26
  • 2021-11-12
  • 2021-07-14
  • 2022-12-23
  • 2021-07-16
  • 2022-02-07
猜你喜欢
  • 2022-02-24
  • 2021-12-19
  • 2022-12-23
  • 2021-04-04
  • 2022-02-27
  • 2021-12-06
  • 2021-12-09
相关资源
相似解决方案