2017-07-24 131 views
0

我都有以下錯誤:應用程序崩潰,當我嘗試刪除標題欄

Missing classes One or more layouts are missing the layout_width or layout_height attributs

element activity is not allowed here

這裏是我的佈局

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.niklas.uebungsrechner.MainActivity" 
tools:layout_editor_absoluteY="81dp" 
tools:layout_editor_absoluteX="0dp"> 

<activity android:name=".MainActivity" 
    android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 
+1

您不能在佈局中進行活動。活動標籤應該只在清單中使用 –

回答

3

你應該遷出:

<activity android:name=".MainActivity" 
android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 

從您的代碼,並與最終的xml:

</android.support.constraint.ConstraintLayout> 
+1

而這首先應該在你的Android Manifest – cjnash

+0

好的謝謝我不知道它必須在清單 – Niklas

+0

但它是stil崩潰時,我有這個android:theme =「@ android:style/Theme.NoTitleBar「(我的確如Vlado Pandzic所說) – Niklas

1

你也可以在onCreate方法添加這段代碼的活動的java文件中。通過這種方式,您可以輕鬆選擇哪個活動有一個標題,哪個活動沒有標題。

ActionBar ab = getSupportActionBar(); ab.hide();

0

這應該是你的manifest.xml文件不是在你的佈局文件

<activity android:name=".MainActivity" 
    android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 
0

這應該是你的佈局文件:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.niklas.uebungsrechner.MainActivity" 
tools:layout_editor_absoluteY="81dp" 
tools:layout_editor_absoluteX="0dp"> 

</android.support.constraint.ConstraintLayout> 

這應該是你的mainfest文件:

<activity android:name=".MainActivity" 
android:theme="@android:style/Theme.NoTitleBar"> 
</activity> 

檢查res文件夾中的values \ styles.xml文件以查看基本應用程序主題。在上面的代碼中將其替換爲Manifest中的Theme.NoTitleBar。

與您的佈局XML相關的活動的java文件,使用權後,該代碼,

setContentView(R.layout.your_layout_file); 
try { 
     getSupportActionBar().hide(); 
    } catch (NullPointerException npe) { 
     npe.printStackTrace(); 
    } 

這將隱藏標題欄。

相關問題