先直接给出效果图:
思路:
通过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文件了,下面就给出这两个布局文件的代码:
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:
custom_button1.xml :
>
custom_button.xml :
>
上面来那个按钮样式中用到的两张图片为:
nofocused.png :
focused.png :
就这么多了,为了方便有需要的人,这里直接给出源码的下载地址:
http://download.csdn.net/source/3480914