Android Prevent Screen Rotate / Configuration Change

Jul 12, 2019
Lock to Portrait Mode only

Edit AndroidManifest.xml.

<manifest ...>
    <application ...>
        <activity
            android:name=".view.QuoteMakerXActivity"
            android:label="@string/title_activity_quotemakerx"
            android:theme="@style/AppTheme.NoActionBar"
            android:screenOrientation="portrait">
    </application>
</manifest>

Or lock screen programatically.

class QuoteMakerXActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {        AndroidInjection.inject(this)        super.onCreate(savedInstanceState)        setContentView(R.layout.quotemakerx)        setSupportActionBar(toolbar)        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT    }}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.