gpt4 book ai didi

java - Android Studio - 为什么 ActionBar 总是显示,即使在完全禁用时也是如此?

转载 作者:行者123 更新时间:2023-11-30 01:49:23 26 4
gpt4 key购买 nike

我最近开始进行 Android 应用程序开发,遇到了 ActionBar 的问题。我知道这个问题已被问过几次,因此我根据我在其他文章中看到的内容进行了必要的更改。

目前,我的主要 Activity 如下所示:image

如您所见,屏幕顶部有一个蓝色条,就在 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);
}
}

activity_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>

content_main.xml

<?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>

AndroidManifest.xml

<?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>

styles.xml

<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" />

关于java - Android Studio - 为什么 ActionBar 总是显示,即使在完全禁用时也是如此?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com