天天看點

Android--鎖定橫屏、豎屏、去标題全屏

xml檔案中設定:

Android--鎖定橫屏、豎屏、去标題全屏

<!-- android:screenorientation="portrait" 豎屏   

android:screenorientation="landscape " 橫屏   

android:screenorientation="unspecified" 未指明方向   

-->   

<activity   

            android:label="@string/app_name"   

            android:name=".lockthescreenactivity"   

            android:screenorientation="portrait"   

  ></activity>   

b)代碼實作如下:

Android--鎖定橫屏、豎屏、去标題全屏

@override   

    public void oncreate(bundle savedinstancestate) {   

        super.oncreate(savedinstancestate);   

        setrequestedorientation(activityinfo.screen_orientation_landscape);// 橫屏   

 //setrequestedorientation(activityinfo.screen_orientation_portrait) 豎屏   

        setcontentview(r.layout.main);   

    }   

螢幕會自動切換時,預設狀态的應用程式,會重新調用oncreate,相當于重新啟動了一次應用程式。同時,layout可能因為橫屏帶來不能合理适配的問題。為了解決旋屏和鍵盤切換引起的程式重新開機問題,還需要增加一個屬性:android:configchanges。這個屬性可以了解為一個監聽器,它将攔截旋屏和鍵盤切換事件,阻止程式重新開機而變為回調onconfigurationchanged方法。這裡常用的屬性取值為:keyboardhidden|orientation。

去标題

Android--鎖定橫屏、豎屏、去标題全屏

<span style="font-size:14px;">public void oncreate(bundle savedinstancestate) {   

    this.requestwindowfeature(window.feature_no_title);  

  }</span>  

全屏

Android--鎖定橫屏、豎屏、去标題全屏

 this.getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);  

  }</span>  

轉載:http://blog.csdn.net/chaoyu168/article/details/51005765

繼續閱讀