Android: пользовательский AlertDialog - PullRequest
6 голосов
/ 21 января 2012

Я создал пользовательский alerttdialog с помощью следующего кода:

AlertDialog.Builder builder;
AlertDialog alertDialog;

LayoutInflater inflater = (LayoutInflater)ActivityName.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_layout,(ViewGroup)findViewById(R.id.layout_root));

                builder = new AlertDialog.Builder(getParent());
                builder.setView(layout);
                alertDialog = builder.create();
                alertDialog.show();

Проблема в том, что всплывающее окно окружено фоном диалога по умолчанию с собственным пустым пространством заголовка (так как заголовок не установлен).Как мне это убрать.Я пытался поставить пользовательский стиль через ContextThemeWrapper, как builder = new AlertDialog.Builder(new ContextThemeWrapper(getParent(), R.style.CustomDialogTheme));

, но он не работает.Как я могу это сделать?!!!Заранее спасибо.Пользовательский стиль XML приведен ниже:

<style name="CustomDialogTheme" parent="android:style/Theme.Dialog.Alert">
            <item name="android:windowIsFloating">false</item>
            <item name="android:windowNoTitle">true</item>
        </style>

This is the output on the emulator

Ответы [ 2 ]

16 голосов
/ 21 января 2012

использовать следующие

Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);

Раздуйте свой макет и установите вид содержимого диалога и

dialog.setContentView(view);
7 голосов
/ 21 января 2012
AlertDialog dialog = new AlertDialog.Builder(this)
.setView(getLayoutInflater().inflate(R.layout.custom_dialog, null))
.create();

Для прослушивания событий пользовательского интерфейса:

View view = getLayoutInflater().inflate(R.layout.custom_dialog, null);
Button btn = (Button)view.findViewById(R.id.the_id_of_the_button);
btn.setOnClickListener(blah blah);
AlertDialog dialog = new AlertDialog.Builder(this)
  .setView(view)
  .create();
...