Ahmad El Ali
Ahmad El Ali

Reputation: 19

How to delete the default bar in android studio?

I am currently developing my first app in android studio and i am facing a problem that i tried to fix for a while now. I am trying to remove the first action bar. I tried changing the theme to a .noActionBar one but to result Please check out the image for a visual explanation

enter image description here

this is my 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"
tools:context="com.example.user.survay_1.SecondActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_red_light"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/toolbar2"
    android:background="#00a4f9"
    android:visibility="visible">

</android.support.v7.widget.RecyclerView>

Upvotes: 0

Views: 120

Answers (5)

Vikas singh
Vikas singh

Reputation: 3879

declare custom theme in your style.xml file like this..

<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item> 
</style>

then in your manifest give your activity theme like this..

    <activity android:name=".ActivityName"
           android:theme="@style/AppThemeNoActionBar"> 
    </activity>

Upvotes: 0

Omkar
Omkar

Reputation: 3100

change your theme NoActionBar at styles.xml

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

also add

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Upvotes: 2

Dumbo
Dumbo

Reputation: 1827

You can do it in two ways.
First way is to disable it in styles.xml file:

styles.xml

<style name="CustomTheme.NoActionBar" parent="CustomTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

And in your AndroidManifest.xml you can use it for all activities:

<application android:theme="@style/CustomTheme.NoActionBar">  

Or for one activity only:

<activity android:theme="@style/CustomTheme.NoActionBar">  

The second way is to hide action bar from your activity:

Activity.class

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

Upvotes: 0

Santanu Sur
Santanu Sur

Reputation: 11477

getSupportActionBar().hide();

In your Activity just use this :- only one line

Upvotes: 0

MohammadAli
MohammadAli

Reputation: 3456

write below code in Style.xml:

<style name="LoginTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>

Now u call this theme in manifest.xml with adding this line android:theme="@style/LoginTheme"

See manifest.xml look like :

<activity
   android:name=".MainActivity"
   android:theme="@style/LoginTheme"
   android:windowSoftInputMode="stateHidden" />

Upvotes: 0

Related Questions