<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>
Motivo:
el color de la fuente se establece en blanco en el tema personalizado, lo que hace que no se muestre el texto del botón AlertDialog, pero la función del botón sigue ahí.
método uno:
Después de mostrar (), establezca el color de fuente del botón.
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);
Método dos:
AlertDialog utiliza un estilo personalizado.
<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();