簡體   English   中英

Android:從應用程序中刪除頂部欄嗎?

[英]Android: Remove the top bar from an app?

我正在嘗試從應用程序中刪除頂部欄。 我嘗試在xml文件中編寫

<activity

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

</activity>

但這給了我錯誤:

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

我也嘗試在OnCreate方法之后使用代碼:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    this.setContentView(R.layout.your_layout_name_here); 

但這也會崩潰....我該怎么辦? 謝謝!

您可以將默認主題保留在AndroidManifest文件中。 您看到標題欄的唯一原因是。

<activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

您可以添加

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

這是因為您的活動正在擴展ActionBarActivity。 您可以通過擴展Activity來代替它。

public class MainActivity extends Activity

我希望這能解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM