Android: allow portrait and landscape for tablets, but force portrait on phone? -
i tablets able display in portrait , landscape (sw600dp or greater), phones restricted portrait only. can't find way conditionally choose orientation. suggestions?
here's way using resources , size qualifiers.
put bool resource in res/values bools.xml or whatever (file names don't matter here):
<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="portrait_only">true</bool> </resources>
put 1 in res/values-sw600dp , res/values-xlarge:
<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="portrait_only">false</bool> </resources>
see this supplemental answer adding these directories , files in android studio.
then, in oncreate method of activities can this:
if(getresources().getboolean(r.bool.portrait_only)){ setrequestedorientation(activityinfo.screen_orientation_portrait); }
devices more 600 dp in smallest width direction, or x-large on pre-android 3.2 devices (tablets, basically) behave normal, based on sensor , user-locked rotation, etc. else (phones, pretty much) portrait only.
Comments
Post a Comment