0

我有一个 Android 应用程序,它首先显示一个对话框。当我将方向设置为纵向并在 Android 3.1 模拟器上运行时,会显示对话框,但一旦用户关闭它,它就会再次显示。这不会发生在 3.2 模拟器上或未设置方向。如何防止对话框在 Android 3.1 上显示两次,方向设置为纵向?

这是代码:

public class TestActivity extends Activity {    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        showDialog(0);
    }

    protected Dialog onCreateDialog(int id) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Message.")
            .setPositiveButton("Ok.", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // nothing
                }
            });         
        return builder.create();
    }
}

这是清单:

<uses-sdk android:minSdkVersion="7" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TestActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

当我的模拟器打开时,它是横向的,如果这很重要的话。

4

1 回答 1

3

我发现了这个:android:configChanges。希望它可以帮助你:-)

例如:

<activity
    ...
    android:configChanges="orientation|keyboardHidden"" />
于 2012-03-29T01:21:20.087 回答