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-开发者_如何学Gohdpi 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.
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.
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"/>
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");
}
精彩评论