没有设置"窗口没有标题"无法运行Android应用程序to" true"

时间:2016-03-02 16:26:57

标签: android styles statusbar

有些东西让我的应用程序崩溃了。我不确定为什么我需要运行绘图应用程序

我的styles.xml文件:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>


<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

这是我的styles.xml v21文件

<resources>
        <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">true</item>
            **<item name="windowNoTitle">true</item>**
            <item name="android:windowDrawsSystemBarBackgrounds">true</item>
            <item name="android:statusBarColor">@android:color/transparent</item>
        </style>

</resources>

如果我将上述设置为false,我的绘图应用程序将崩溃。

我的drawingcontent.xml

  <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/drawing_main"
        tools:context=".DrawingActivity">


            android:id="@+id/custom_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/toolbar_bottom" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_bottom"
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            android:visibility="gone"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            android:src="@android:drawable/ic_dialog_email" />

    </RelativeLayout>

另一个是我的drawing_main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    android:fitsSystemWindows="true"
    tools:context=".DrawingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_top"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <com.example.kahheng.smartchat.CustomView
        android:id="@+id/custom_view"
        android:layout_below="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/toolbar_bottom" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_bottom"
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</RelativeLayout>

请告诉我我的代码有什么问题,为什么我必须删除状态栏? 有人有个主意吗?

我从这里得到了代码 http://www.valokafor.com/android-drawing-app-tutorial-pt-2/

1 个答案:

答案 0 :(得分:0)

您在XML中使用工具栏,我认为您正在使用该工具栏作为ActionBar。因此,您无法从主题中获得另一个操作栏(一个活动中只能有一个操作栏)。因此,要将工具栏用作操作栏,您必须使用&#34; window no title&#34;或继承其中一个.NoActionBar主题。