我最近开始使用Android应用程序开发,并遇到了ActionBar的问题。我知道这个问题已被问过几次了,所以我从其他文章中看到了我所做的更改。
目前,我的主要活动如下: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
非常感谢任何和所有帮助。谢谢!
答案 0 :(得分:1)
从您的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" />