Skip to content

Instantly share code, notes, and snippets.

@yung-yu
Created May 15, 2017 03:46
Show Gist options
  • Save yung-yu/7ca188bb8b0d0f9b3222c8892a630996 to your computer and use it in GitHub Desktop.
Save yung-yu/7ca188bb8b0d0f9b3222c8892a630996 to your computer and use it in GitHub Desktop.
讓Acitvity切換橫向直向不要重啟
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