空白alertDialog

时间:2017-02-16 08:30:35

标签: android android-alertdialog

我有一个奇怪的问题。 我有一个简单的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>`

正如我所说,我可以看到图标,但不能看到标题或信息。

由于

1 个答案:

答案 0 :(得分:1)

试试这个:

162M

传递Dialog类中的Activity上下文并使用它

同样在你的:

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();
}

现在在Dialog类中使用:

//in activity
MyDialogClass dialog=new MyDialogClass(this);