Java Android Studio-为什么ActionBar总是显示,即使完全禁用?

Java Android Studio-为什么ActionBar总是显示,即使完全禁用?,java,android,xml,android-studio,android-actionbar,Java,Android,Xml,Android Studio,Android Actionbar,我最近刚开始Android应用程序开发,遇到了ActionBar的一个问题。我知道这个问题已经被问过好几次了,所以我从其他文章中看到了一些必要的变化 目前,我的主要活动如下: 正如您所看到的,在通知栏的正下方,屏幕顶部有一个蓝色栏,其中应该有一个操作栏。我的所有应用程序主题(我相信)都设置为NoActionBar。我想去掉这个蓝条,这样我就可以用整个屏幕来放置我的内容 我的代码如下: Main_Activity.Java package ryanpx2016.golftracker; impo

我最近刚开始Android应用程序开发,遇到了ActionBar的一个问题。我知道这个问题已经被问过好几次了,所以我从其他文章中看到了一些必要的变化

目前,我的主要活动如下:

正如您所看到的,在通知栏的正下方,屏幕顶部有一个蓝色栏,其中应该有一个操作栏。我的所有应用程序主题(我相信)都设置为NoActionBar。我想去掉这个蓝条,这样我就可以用整个屏幕来放置我的内容

我的代码如下:

Main_Activity.Java

package ryanpx2016.golftracker;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.content.Intent;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button regularScorePageActivityButton = (Button)findViewById(R.id.scoreSheetButton);
        regularScorePageActivityButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                startActivity(new Intent(MainActivity.this, RegularScorePageActivity.class));
           }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
活动\u main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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=".MainActivity">

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

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

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

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:background="@drawable/scoresheet_button"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/scoresheet_button"
        android:id="@+id/scoreSheetButton"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <Button
        android:background="@drawable/course_buttons"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/my_golf_courses_button"
        android:id="@+id/myGolfCoursesButton"
        android:layout_below="@+id/scoreSheetButton"
        android:layout_alignStart="@+id/scoreSheetButton"
        android:layout_marginTop="35dp" />

    <Button
        android:background="@drawable/course_buttons"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/my_minigolf_courses_button"
        android:id="@+id/myMinigolfCoursesButton"
        android:layout_marginTop="35dp"
        android:layout_below="@+id/myGolfCoursesButton"
        android:layout_centerHorizontal="true" />


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ryanpx2016.golftracker" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



        <activity
            android:name=".RegularScorePageActivity"
            android:label="@string/title_activity_regular_score_page"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="ryanpx2016.golftracker.RegularScorePageActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- 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.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>



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

</resources>

content\u main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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=".MainActivity">

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

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

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

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:background="@drawable/scoresheet_button"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/scoresheet_button"
        android:id="@+id/scoreSheetButton"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <Button
        android:background="@drawable/course_buttons"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/my_golf_courses_button"
        android:id="@+id/myGolfCoursesButton"
        android:layout_below="@+id/scoreSheetButton"
        android:layout_alignStart="@+id/scoreSheetButton"
        android:layout_marginTop="35dp" />

    <Button
        android:background="@drawable/course_buttons"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/my_minigolf_courses_button"
        android:id="@+id/myMinigolfCoursesButton"
        android:layout_marginTop="35dp"
        android:layout_below="@+id/myGolfCoursesButton"
        android:layout_centerHorizontal="true" />


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ryanpx2016.golftracker" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



        <activity
            android:name=".RegularScorePageActivity"
            android:label="@string/title_activity_regular_score_page"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="ryanpx2016.golftracker.RegularScorePageActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- 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.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>



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

</resources>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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=".MainActivity">

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

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

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

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:background="@drawable/scoresheet_button"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/scoresheet_button"
        android:id="@+id/scoreSheetButton"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <Button
        android:background="@drawable/course_buttons"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/my_golf_courses_button"
        android:id="@+id/myGolfCoursesButton"
        android:layout_below="@+id/scoreSheetButton"
        android:layout_alignStart="@+id/scoreSheetButton"
        android:layout_marginTop="35dp" />

    <Button
        android:background="@drawable/course_buttons"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/my_minigolf_courses_button"
        android:id="@+id/myMinigolfCoursesButton"
        android:layout_marginTop="35dp"
        android:layout_below="@+id/myGolfCoursesButton"
        android:layout_centerHorizontal="true" />


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ryanpx2016.golftracker" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



        <activity
            android:name=".RegularScorePageActivity"
            android:label="@string/title_activity_regular_score_page"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="ryanpx2016.golftracker.RegularScorePageActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- 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.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>



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

</resources>

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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=".MainActivity">

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

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

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

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:background="@drawable/scoresheet_button"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/scoresheet_button"
        android:id="@+id/scoreSheetButton"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <Button
        android:background="@drawable/course_buttons"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/my_golf_courses_button"
        android:id="@+id/myGolfCoursesButton"
        android:layout_below="@+id/scoreSheetButton"
        android:layout_alignStart="@+id/scoreSheetButton"
        android:layout_marginTop="35dp" />

    <Button
        android:background="@drawable/course_buttons"
        android:layout_width="185dp"
        android:layout_height="wrap_content"
        android:text="@string/my_minigolf_courses_button"
        android:id="@+id/myMinigolfCoursesButton"
        android:layout_marginTop="35dp"
        android:layout_below="@+id/myGolfCoursesButton"
        android:layout_centerHorizontal="true" />


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ryanpx2016.golftracker" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



        <activity
            android:name=".RegularScorePageActivity"
            android:label="@string/title_activity_regular_score_page"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="ryanpx2016.golftracker.RegularScorePageActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- 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.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>



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

</resources>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的
我相信这可能与工具栏有关,但话说回来,我不一定知道我在说什么:D


非常感谢您的任何帮助。谢谢

从activity_main.xml中删除此内容:

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

Ohh我明白了;解决了这个问题。你是救命恩人!谢谢,谢谢@斯坦诺伊科维奇