如何实现一个自定义AlertDialog?


import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;

.....

        int choiceItem = -1;

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        String[] choices = getResources().getStringArray(R.array.gif_auto_play_type);
        int type = PreferencesUtil.getInstance(this).getAutoPlaySetting();
        builder.setSingleChoiceItems(choices, type, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                choiceItem = which;
            }
        });

        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                PreferencesUtil.getInstance(SettingActivity.this).saveAutoPlaySetting(choiceItem);
            }
        });
        builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        builder.show();
<activity
            android:name=".setting.SettingActivity"
            android:configChanges="orientation|screenSize"
            android:screenOrientation="portrait"
            android:theme="@style/dialog_style"/>
    <string-array name="gif_auto_play_type">
        <item>Mobile data and WiFiitem>
        <item>WiFi onlyitem>
        <item>Neveritem>
    string-array>

你可能感兴趣的:(AndroidStudio)