创建一个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();
创建Style
<style name="dialog_style" parent="Theme.AppCompat.Light.DialogWhenLarge">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/dialog_color</item>
<item name="android:listChoiceIndicatorSingle">@drawable/dialog_single_choice</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="windowNoTitle">true</item>
</style>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_rb_selected" android:state_checked="true" /><!--选中时效果-->
<item android:drawable="@drawable/ic_rb_unselected" android:state_checked="false" /><!--未选中时效果-->
<!-- 修改成你自己的图片就可以了 -->
</selector>
<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 WiFi</item>
<item>WiFi only</item>
<item>Never</item>
</string-array>