在Android實現沒有標題欄的方法有兩種:
在代碼中添加
- requestWindowFeature(Window.FEATURE_NO_TITLE);
在清單文件AndroidManifest.xml中添加
- 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="http://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>
效果圖:
650) this.width=650;" height=151>
如果想讓窗口全屏顯示:
將下面兩段代碼分別替換上面的兩段設置無標題的代碼就可以了
- getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
- WindowManager.LayoutParams. FLAG_FULLSCREEN);
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
效果圖:
650) this.width=650;">