DialogFragments与设备API级< 11 [英] DialogFragments with devices api level < 11

查看:131
本文介绍了DialogFragments与设备API级< 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在制备蜂窝状项目/叉1.6±向后兼容的过程。

I am in the process of making a honeycomb project/fork backwards compatible with 1.6+.

...它给了我的灵活性,把任何一个对话框或全屏幕元素。

Based on the documentation provided by Google/Android I decided to build off all my fragments off DialogFragments which worked great for honeycomb...it gives me the flexibility to put anything as a dialog or 'full screen' element.

我现在已经纳入了兼容性工具包,并动了我的进口和方法调用了这一点。现在,我在2.3我试图推出一个相同的目的,但我得到这个问题的:

I've now incorporated the compatibility kit and moved my imports and method calls over to that. Now that I'm on 2.3 I am trying to launch an identical intent but I receive this issue:

java.lang.IllegalStateException: DialogFragment can not be attached to a container view

的文档 DialogFragment 表明,它可以为片段执行,当你不想要的对话框/弹出功能。

The documentation for DialogFragment suggests that it can perform as Fragment when you don't desire the dialog/popup functionality.

推荐答案

我设法在 DialogFragment.java 妥善解决的兼容包这样的:

I managed to fix this properly in DialogFragment.java of the Compatibility Package:

更改线路74: 布尔mShowsDialog = FALSE;

注释掉行232: // mShowsDialog = mContainerId == 0;

然后改变两个节目的方法如下:

Then change the two show methods to this:

public void show(FragmentManager manager, String tag) {
    this.setShowsDialog(true);
    FragmentTransaction ft = manager.beginTransaction();
    ft.add(this, tag);
    ft.commit();
}

// JavaDoc removed
public int show(FragmentTransaction transaction, String tag) {
    this.setShowsDialog(true);
    transaction.add(this, tag);
    mRemoved = false;
    mBackStackId = transaction.commit();
    return mBackStackId;
}

基本上,他们写支持,但切换到对话框/嵌入式不起作用之间切换。

Basically, they did write in support but the toggle to switch between dialog/embedded doesn't work.

所以在这里我们默认为嵌入式,然后设置为显示为之前我们表现出来的对话框。

So here we default to embedded, and then set to show as a dialog just before we show it.

这篇关于DialogFragments与设备API级< 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆