歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發教程:實現沒有標題欄的窗口和全屏顯示

Android開發教程:實現沒有標題欄的窗口和全屏顯示

日期:2017/3/1 10:36:27   编辑:Linux編程

在Android實現沒有標題欄的方法有兩種:

在代碼中添加

  1. requestWindowFeature(Window.FEATURE_NO_TITLE);

在清單文件AndroidManifest.xml中添加

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

具體的代碼如下:

第一種:

MainActivity.java

  1. package com.lingdududu.test;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.Window;
  5. public class MainActivity extends Activity {
  6. /** Called when the activity is first created. */
  7. private boolean catchHomeKey = false;
  8. public void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  11. setContentView(R.layout.main);
  12. }
  13. }

第二種:

AndroidManifest.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.lingdududu.test"
  4. android:versionCode="1"
  5. android:versionName="1.0">
  6. <uses-sdk android:minSdkVersion="10" />
  7. <application android:icon="@drawable/icon" android:label="@string/app_name">
  8. <activity android:name=".MainActivity"
  9. android:label="@string/app_name"
  10. android:theme="@android:style/Theme.NoTitleBar" >
  11. <intent-filter>
  12. <action android:name="android.intent.action.MAIN" />
  13. <category android:name="android.intent.category.LAUNCHER" />
  14. </intent-filter>
  15. </activity>
  16. </application>
  17. </manifest>

效果圖:

650) this.width=650;" height=151>

如果想讓窗口全屏顯示:

將下面兩段代碼分別替換上面的兩段設置無標題的代碼就可以了

  1. getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
  2. WindowManager.LayoutParams. FLAG_FULLSCREEN);

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

效果圖:

650) this.width=650;">

Copyright © Linux教程網 All Rights Reserved