簡體   English   中英

Android App如何暫時旋轉屏幕方向

[英]Android App How to rotation screen orientation temporarily

有什么辦法可以暫時停止旋轉屏幕,執行還原操作? 要求不能關閉重力感應器,它只能禁止屏幕旋轉。

要禁用方向更改,您需要告知Android您要自己處理。

為此,請在mainfest.xml中的活動中添加以下內容:

android:configChanges="orientation"

現在,在“活動”中覆蓋以下內容:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

如果您在此處不加載新布局,則只需保持方向即可。

您可以在此處找到更多詳細信息: http : //developer.android.com/guide/topics/resources/runtime-changes.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM