Rajappa R
Rajappa R

Reputation: 31

Two actionbars are displaying, when i set custom actionbar

I stetted custom action-bar to my activity, after adding custom action-bar it is displaying on top correctly but the default action-bar is still displaying next to custom action-bar. See the below screenshot I want to remove that black action-bar if anyone knows about this please help me here

I refereed this link to add custom action-bar

Please refer below screenshot I want to remove dark action-bar

please refer this screenshot I want to remove dark action-bar

Upvotes: 0

Views: 1032

Answers (3)

Aleksandar Stefanović
Aleksandar Stefanović

Reputation: 1593

Firstly, if you want a custom Action Bar as a beginner, I would recommend using the Toolbar widget. It works as a regular widget, that replaces the Action Bar. Once you've put the Toolbar widget in your layout, you should set it as a support action bar, in your onCreate method:

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

This works only if you're using the AppCompatActivity as a base of your Activity. If not, you'll have to rework it.

After you've extending AppCompatActivity instead of Activity, you should change your theme, to a .NoActionBar version, such as Theme.AppCompat.Light.NoActionBar, so that the system does not supply an Action Bar by itself, but rather uses the one you created (you'll get an error if you don't do this).

Once you've done this, it should work!

Upvotes: 1

Abdelalim Allam
Abdelalim Allam

Reputation: 36

you have to make your activity theme in the AndroidManifest.xml

<activity
        android:name="YOUR ACTIVITY NAME"
        android:theme="@style/AppTheme" />

set style in res/values/styles.xml

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

Upvotes: 1

Matias Elorriaga
Matias Elorriaga

Reputation: 9150

add this to your styles.xml file

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item> <!-- For 2.x version  -->
    </style>
</resources>

and use that theme in your manifest file

android:theme="@android:style/Theme.AppCompat.Light.NoActionBar" 

Upvotes: 1

Related Questions