Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 實現全屏與隱藏標題欄的兩種方法

編輯:關於 Android 程式設計

在 Android 中隱藏標題欄主要有兩種做法,一種是通過代碼設置,另一種是通過清單文件配置。

方法一,在代碼中調用:

 requestWindowFeature(Window.FEATURE_NO_TITLE); 

方法二,在清單文件 AndroidManifest.xml 中為 Activity 指定主題:

 android:theme="@android:style/Theme.NoTitleBar" 

下面分別給出兩種方式的完整示例代碼。

第一種:代碼方式

 MainActivity.java package com.lingdududu.test; import android.app.Activity; import android.os.Bundle; import android.view.Window; public class MainActivity extends Activity { /** Called when the activity is first created. */ private boolean catchHomeKey = false; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); } } 

第二種:清單文件方式

 AndroidManifest.xml <?xml version="1.0" encoding="utf-8?> <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="com.lingdududu.test" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

效果圖:

如果需要讓窗口全屏顯示:

只要把下面這兩段代碼分別替換掉上面隱藏標題欄的對應設置即可。

 getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN); android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 

效果圖:

以上就是 Android 全屏與隱藏標題欄效果的代碼示例和效果展示,希望能對大家有所幫助。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved