我想自定义对话框来仅更改警报的正文。我想在这个屏幕截图中输出:
但我不知道这种类型的对话。非常感谢任何帮助。
答案 0 :(得分:2)
是的,您可以根据需要更改对话框。您可以通过创建自定义对话框来完成此操作。 Step1。在res
中的String文件中创建一个样式 <style name="myQuitDialog" parent="android:Theme.Dialog">
<item name="android:gravity">center_horizontal</item>
</style>
第二步。在布局中创建xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_quit"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image which u want to show"
>
步骤3。在src中编写自定义对话框的代码
class Custom_Dialog extends Dialog {
protected Custom_Dialog(Context context, int theme) {
super(context, theme);
// TODO Auto-generated constructor stub
}
}
private void show_alert() {
final Custom_Dialog alertbox = new Custom_Dialog(this, R.style.myQuitDialog);
Window window = alertbox.getWindow();
window.setBackgroundDrawableResource(android.R.color.transparent);
window.requestFeature(window.FEATURE_NO_TITLE);
alertbox.show();
alertbox.setCancelable(true);
alertbox.setCanceledOnTouchOutside(true);
alertbox.dismiss();
}
}
答案 1 :(得分:2)
请查看以下链接
http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application
http://www.thiyagaraaj.com/articles/android-articles/customdialogboxpopupusinglayoutinandroid
http://www.thecompboy.com/2011/11/android-tutorial-custom-dialog.html
http://www.mysamplecode.com/2011/06/android-custom-dialog-box-sample-code.html
答案 2 :(得分:1)
你可以自己创建活动,并在AndroidManifest.xml中为它设置android:theme="@android:style/Theme.Dialog"
属性,这样它就像是对话框窗口