Created
May 15, 2017 03:46
-
-
Save yung-yu/7ca188bb8b0d0f9b3222c8892a630996 to your computer and use it in GitHub Desktop.
讓Acitvity切換橫向直向不要重啟
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AndroidManifest.xml | |
----------------------------------- | |
<activity | |
android:name=".DemoActivity" | |
android:screenOrientation="unspecified" | |
android:configChanges="orientation|screenSize" | |
/> | |
DemoActivity.java | |
------------------------------- | |
public class DemoActivity extends Activity{ | |
... | |
@Override | |
public void onConfigurationChanged(Configuration newConfig) { | |
super.onConfigurationChanged(newConfig); | |
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { | |
Log.d(TAG, "screen landscape"); | |
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { | |
Log.d(TAG, "screen portrait"); | |
} | |
} | |
... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment