Мне было интересно, может ли кто-нибудь мне помочь. Я пытаюсь создать собственный AlertDialog. Для этого я добавил следующую строку кода в styles.xml
<resources>
<style name="CustomAlertDialog" parent="android:Theme.Dialog.Alert">
<item name="android:windowBackground">@drawable/color_panel_background</item>
</style>
</resources>
- color_panel_background.9.png находится в папке для рисования. Это также доступно в папке Android SDK res.
Основным видом деятельности является следующее.
package com.customdialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
public class CustomDialog extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setTheme(R.style.CustomAlertDialog);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("HELLO!");
builder .setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//dialog.cancel();
}
});
AlertDialog alertdialog = builder.create();
alertdialog.show();
}
}
Чтобы применить тему к AlertDialog, мне нужно было установить тему в текущем контексте.
Тем не менее, я просто не могу заставить приложение показывать настроенный AlertDialog. Кто-нибудь может мне помочь с этим?