Skip to content

Instantly share code, notes, and snippets.

@maiconhellmann
Created November 30, 2020 13:46
Show Gist options
  • Save maiconhellmann/89d346e898a85ee2458a8aad03eabc4c to your computer and use it in GitHub Desktop.
Save maiconhellmann/89d346e898a85ee2458a8aad03eabc4c to your computer and use it in GitHub Desktop.
screenOrientation - smartphone = PORTRAIT and tablet = DYNAMIC
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">true</bool>
</resources>
<activi
android:name=".MyAmazingActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="behind"/>
class MyAmazingActivity: AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (resources.getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR)
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">false</bool>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment