gpt4 book ai didi

android - 空白警报对话框

转载 作者:太空狗 更新时间:2023-10-29 13:53:37 26 4
gpt4 key购买 nike

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

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

也在你的:

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

现在在你的 Dialog 类中使用:

 Context activity_context;
MyDialogClass(Context context){
this.activity_context=context; //now use activity_context to show alertDialog
}

关于android - 空白警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42268590/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com