2017-07-24 109 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(); 
    } 

这将隐藏标题栏。

相关问题