iamtheexp01
iamtheexp01

Reputation: 3466

Dialog must not be dismiss when screen orientation change

I've created a custom tab activity which has two different drawables for portrait and landscape orientation. The icons for portrait screen is under drawable-hdpi while the images for landscape is under drawable-land-hdpi. As of now, I put config change in the manifest to preserve the dialog's visibility.

android:configChanges="orientation"

Whenever the dialog is shown and user changes the orientation from portrait to landscape, the dialog still shows but the images it uses in tab activity is for portrait mode. That's why the layout for doesn't look right since it didn't use the drawables for landscape. Could someone help me with this? Thanks.

Upvotes: 4

Views: 5135

Answers (3)

i18n
i18n

Reputation: 130

You can perform custom layout implementation by detecting the orientation mode as below:

@Override
public void onConfigurationChanged(Configuration config) 
{
    super.onConfigurationChanged(config);

    if(config.orientation == Configuration.ORIENTATION_LANDSCAPE)
        Log.i("orientation", "Orientation changed to: Landscape");
    else
        Log.i("orientation", "Orientation changed to: Portrait");
}

Upvotes: 0

Deepak
Deepak

Reputation: 61

Add like this in your activity tag in application manifest.xml

<activity android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenSize" android:name=".your.package"/>

Upvotes: 0

Michael
Michael

Reputation: 54705

If you use android:configChanges="orientation" then Android doesn't re-create the activity when the orientation is changed. If you don't want the dialog to be dismissed, just use the Activity.showDialog() method. And if you still want to use android:configChanges="orientation" then you have to change drawables manually in the Activity.onConfigurationChanged() method.

Upvotes: 3

Related Questions