<activity
android:name=".modules.other.SplashActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/SplashBackgroundStyle">
</activity>
<style name="SplashBackgroundStyle" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowBackground">@drawable/app_launch_bg</item>
<item name="android:windowFullscreen">true</item>
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryVariant">@color/white</item>
<item name="colorOnPrimary">@color/white</item>
</style>
原因:
自定义主题 中设置了字体颜色为白色,导致AlertDialog按钮文字显示不出来,但是按钮功能是在的。
方法一:
在show()之后, 设置按钮字体颜色。
AlertDialog dialog = new AlertDialog.Builder(nActivity).setCancelable(false)
.setTitle("提示")
.setMessage("安装应用需要打开未知来源权限,请去设置中开启权限")
.setNegativeButton("取消", null)
.setPositiveButton("立即开启", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startInstallPermissionSettingActivity();
}
}).create();
dialog.show();
// 设置按钮字体颜色
Button btnPos = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
btnPos.setTextColor(Color.RED);
Button btnNeg = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
btnNeg.setTextColor(Color.BLACK);
方法二:
AlertDialog使用自定义的style。
<style name="MyDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
AlertDialog dialog = new AlertDialog.Builder(nActivity, R.style.MyDialog).setCancelable(false)
.setTitle("提示")
.setMessage("安装应用需要打开未知来源权限,请去设置中开启权限")
.setNegativeButton("取消", null)
.setPositiveButton("立即开启", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startInstallPermissionSettingActivity();
}
}).create();
dialog.show();