简体   繁体   中英

How to remove the blue action bar in android?

I am creating an android app but I have some problem I cant remove this blue heading or I don't know how its called, or action bar ? I have tried some methods but they didn't work. 在此输入图像描述

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

    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity"
    android:background="#9AEA30">

    <ImageView
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:id="@+id/imageView"
        android:src="@drawable/discount"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

What did you try?

Just add this in styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

</style>

And

android:theme="@style/AppTheme"

in AndroidManifest.xml in application section.

The easiest way to remove it is to make your Activity extend the Activity class and not the AppCompatActivity .

That is do something like this:

public class MyActivity extends Activity {

}

In your style file (res/values/styles.xml) is declared the style of your project.

For example

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
    </style>

Change "Theme.AppCompat.Light.DarkActionBar" with "Theme.AppCompat.Light.NoActionBar"

like this

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
    </style>

The same can be achieved for Dark themes.

如果您使用的是Android Studio,则可以选择从预览窗口更改主题而无需任何代码。

This method work for me :

Remove this code from following 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" />

may be late but i found a way too just remove the following code from your xml layout

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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>

This is the simplest and cleanest solution IMO:

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM