Android編程設置全屏的方法實例詳解
本文實例講述了Android編程設置全屏的方法。分享給大家供大家參考,具體如下:
在實際的應用程序開發(fā)中,我們有時需要把 Activity 設置成全屏顯示,一般情況下,可以通過兩種方式來設置全屏顯示效果。其一,通過在代碼中可以設置,其二,通過manifest配置文件來設置全屏。
其一:在代碼中設置(如下)
package xiaohang.zhimeng; import android.app.Activity; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class Activity01 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //設置為無標題欄 requestWindowFeature(Window.FEATURE_NO_TITLE); //設置為全屏模式 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //設置為橫屏 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.main); } }
但要注意的是:在代碼中設置的話,設置無標題和設置全屏的兩段代碼要放置在 setContentView(R.layout.main); 這段代碼的前面。要不然會報錯。
其二:在manifest配置文件中設置
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ladygaga.playboy" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name="com.ladygaga.test.ImageSwitcherTest" android:screenOrientation="sensor" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
或:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ladygaga.playboy" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:label="@string/app_name"> <activity android:name="com.ladygaga.test.ImageSwitcherTest" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
在相應的Activity中節(jié)點中添加屬性:
希望本文所述對大家Android程序設計有所幫助。
相關文章
Android開發(fā)之Flutter與webview通信橋梁實現(xiàn)
這篇文章主要為大家介紹了Android開發(fā)之Flutter與webview通信橋梁實現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06Android TextView實現(xiàn)帶鏈接文字事件監(jiān)聽的三種常用方式示例
這篇文章主要介紹了Android TextView實現(xiàn)帶鏈接文字事件監(jiān)聽的方法,結合實例形式分析了鏈接跳轉、setMovementMethod及布局屬性設置三種常用的實現(xiàn)方式,需要的朋友可以參考下2017-08-08基于Android 實現(xiàn)圖片平移、縮放、旋轉同時進行
這篇文章主要介紹了基于Android 實現(xiàn)圖片平移、縮放、旋轉同時進行的相關資料,需要的朋友可以參考下2015-11-11