【问题标题】:Custom AlertDialog not appearing on Jelly Bean果冻豆上没有出现自定义警报对话框
【发布时间】:2012-07-25 14:42:32
【问题描述】:

我在我的应用中包含了一个自定义的 AlertDialog。将我的 Galaxy Nexus 更新为 Jelly Bean 后,不再显示对话框。只有屏幕变暗。对话框周围的过程(如加载数据)运行良好。在较旧的操作系统版本上,代码可以正常工作(包括 ICS 4.0.4)。

无论对话框是在 AsyncTask 中还是在外部创建和显示,都会出现问题。

有没有类似的问题?

代码如下:

public class TLProgressDialog extends AlertDialog{

/*Log tag */
@SuppressWarnings("unused")
private static final String TAG = "TLProgressDialog";

@SuppressWarnings("unused")
private Context context;
private AnimationDrawable animation;

protected TLProgressDialog(Context context) {
    super(context);
    this.context = context;
}

public TLProgressDialog(Context context, boolean cancelable,
        OnCancelListener cancelListener) {
    super(context, cancelable, cancelListener);
    this.context = context;
}

public TLProgressDialog(Context context, int theme) {
    super(context, theme);
    this.context = context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tlprogressdialog);
    ImageView img = (ImageView)findViewById(R.id.dialog_img);
    img.setBackgroundResource(R.drawable.tlprogress_animation);
    animation = (AnimationDrawable) img.getBackground();
    img.post(new Starter());
}

public static TLProgressDialog show(Context context){
    TLProgressDialog dlg = new TLProgressDialog(context);
    dlg.setCanceledOnTouchOutside(false);
    dlg.setCancelable(false);
    dlg.show();
    return dlg;
}

private class Starter implements Runnable {
    public void run() {
        animation.start();
    }
}
}

xml 布局只是一个承载动画图像的 ImageView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/dialog_img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"/>

</RelativeLayout>

【问题讨论】:

  • 我的错,刚刚发现我已经为动画添加了 GIF。这似乎不再起作用了。转换为 PNG 后,它又可以工作了。

标签: android android-alertdialog android-4.2-jelly-bean


【解决方案1】:

您是否为您的应用取消选中“显示通知”? (在 Settings/apps/ 和“显示通知”中检查它)。

【讨论】:

    【解决方案2】:

    我的错,刚刚发现我在动画中包含了 GIF。这似乎不再起作用了。转换为 PNG 后,它又可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 1970-01-01
      相关资源
      最近更新 更多