开发中经常遇到这种弹窗,系统颜色往往不合适,于是我们使用自定义style方式进行设置
String[] cameraNames = new String[]{"camera0","camera1"};
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext(),R.style.alterAialogCustom);
alertBuilder.setSingleChoiceItems(cameraNames, checkedItemIndex, (dialogInterface, i) -> {
dialogInterface.dismiss();
});
alertBuilder.setPositiveButton(getString(R.string.cancel), (dialogInterface, i) -> dialogInterface.dismiss());
AlertDialog alertDialog = alertBuilder.create();
alertDialog.show();
<!-- 自定义alterDialog 样式-->
<style name="alterAialogCustom" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<!-- <item name="android:textColor">#00FF00</item>-->
<!-- <item name="android:typeface">monospace</item>-->
<!-- <item name="android:textSize">10sp</item>-->
<!-- radiobutton 正常颜色-->
<item name="colorControlNormal">#61000000</item>
<!-- radiobutton 选中颜色-->
<item name="colorControlActivated">#1B6FE5</item>
</style>