我有个奇怪的问题。
我有一个简单的alertdialog,我给它传递了一个参数,但是除了图标之外,它是空白的。
这是一种方法:

public class ViewUtil {

//// some code...

public static void showMessagePopup(int titleResId, String message, Context context) {
    new AlertDialog.Builder(context)
            .setTitle(context.getResources().getString(titleResId))
            .setMessage(message)
            .setIcon(R.mipmap.ic_launcher)
            .show();
}

在这里我称之为
public class RedesignNewDriverPopup extends Dialog {
/// some code...

 new PrepareRestApiTask<>(new PrepareRestApiTask.restApiCaller<String>() {
                @Override
                public Call<RestResponse<String>> onRestApiReadyBackgroundRun(String hashedToken,
                                                                              SmartbusClient client) {
                    return client.update_driver(driver.id, req, hashedToken);
                }

                @Override
                public void onEverythingFinishedUIThreadRun(String theData) {
                    updateCallback.afterDriverUpdate();
                    ViewUtil.showMessagePopup(R.string.new_driver, getContext().getResources().getString(R.string.driver_created), getContext());
                    dismiss();
                }

                @Override
                public void onError(Response<RestResponse<String>> response) {
                    ViewUtil.showMessagePopup(R.string.new_driver, getContext().getResources().getString(R.string.login_error), getContext());
                    dismiss();
                }


            }).execute();

这是我的主题:
 `<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="drawerArrowStyle">@style/DrawerArrowToggle</item>
    <item name="android:actionBarStyle">@android:style/Widget.Holo.ActionBar</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
</style>`

如我所说,我可以看到图标,但看不到标题或消息。
谢谢

最佳答案

试试这个:

ViewUtil.showMessagePopup(activity_context.getResources().getString(R.string.new_driver), activity_context.getResources().getString(R.string.driver_created), activity_context);

在对话类中传递活动上下文并使用它
同样在您的:
    public static void showMessagePopup(String titleResId, String message, Context context) {
    new AlertDialog.Builder(context)
            .setTitle(titleResId)
            .setMessage(message)
            .setIcon(R.mipmap.ic_launcher)
            .show();
}

传递上下文:
//in activity
MyDialogClass dialog=new MyDialogClass(this);

现在在对话类中使用:
 Context activity_context;
MyDialogClass(Context context){
this.activity_context=context; //now use activity_context to show alertDialog
}

07-26 02:58