0
public class ReviewActivity extends Activity {
     public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reviewfrag_layout);
         mInflater = (LayoutInflater) ReviewActivity.this.getSystemService( 
                    LAYOUT_INFLATER_SERVICE); 
            ContextThemeWrapper mTheme = new ContextThemeWrapper(this, 
                    R.style.customDialog); 

            mView = mInflater.inflate(R.layout.custom_dialog, null); 
            // mDialog = new Dialog(this,0); // context, theme 

            mDialog = new Dialog(mTheme); 
            mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
            mDialog.setContentView(this.mView); 

               //if i comment below line  code runs otherwise give exception
           mDialog.show();
        }
}

风格:

<style name="customDialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowContentOverlay">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">false</item>

日志消息:10-10 13:20:01.184: E/AndroidRuntime(1417): FATAL EXCEPTION: main 10-10 13:20:01.184: E/AndroidRuntime(1417): android.view.WindowManager$BadTokenException: 无法添加窗口 -- 令牌 android.app.LocalActivityManager$LocalActivityRecord@411eeaa0 无效;您的活动正在运行吗?10-10 13:20:01.184: E/AndroidRuntime(1417): 在 android.view.ViewRootImpl.setView(ViewRootImpl.java:585) 10-10 13:20:01.184: E/AndroidRuntime(1417): 在 android. view.WindowManagerImpl.addView(WindowManagerImpl.java:326) 10-10 13:20:01.184: E/AndroidRuntime(1417): 在 android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224) 10-10 13:20: 01.184: E/AndroidRuntime(1417): 在 android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149) 10-10 13:20:01.184: E/AndroidRuntime(1417): 在 android.view。

4

1 回答 1

0

这是上下文问题。如果您从 Activity 组打开此活动,则不要使用 setContentView(R.layout.xxxx) 使用以下内容:

查看 viewToLoad = LayoutInflater.from(getParent()).inflate(R.layout.XXXX, null); this.setContentView(viewToLoad);

希望它会起作用

于 2013-03-30T07:08:19.927 回答