DialogFragments与设备API级< 11设备、DialogFragments、API、LT

2023-09-04 04:01:42 作者:天生傲骨、怎能屈服

我在制备蜂窝状项目/叉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.

 
精彩推荐