0

I am creating an android app, i am trying to hide default action bar and us my own custom toolbar as action bar but the problem is that default navigation icon and title of action bar are not being hidden and when i open navigation drawer from right side my custom navigation icon from left side hides and android's default navigation icon is displayed instead. i have tried using NoActionBar and NoTheme styles too but its not working. Here is a sample of my code, where i am going wrong

Any help will be appreciated.

public class MyActivity extends AppCompatActivity
{
    Toolbar main_toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        setUpToolBar();
    }

    public void setUpToolBar() 
    {
        main_toolbar=(Toolbar)findViewById(R.id.toolbar)
        //set up the home_main_toolbar
        android.app.ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
        setSupportActionBar(main_toolbar);
        if (activity.getSupportActionBar() != null)
            main_toolbar.setNavigationIcon(R.drawable.img_toolbar);
        main_toolbar.setNavigationOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View view) {
               //Open navigation drawer
            }
        });
    }
}
Komal12
  • 3,340
  • 4
  • 16
  • 25
User
  • 692
  • 2
  • 11
  • 29

3 Answers3

3
<activity android:name=".MainActivity" android:screenOrientation="portrait" android:theme="@style/AppTheme.NoActionBar" />

use this code in your android menifest , surely it will work

2

try it in manifest where your activity is defined.

android:theme="@style/AppTheme.NoActionBar"
Aashutosh Kumar
  • 183
  • 4
  • 12
1

Go to Styles.xml

add this style there

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

and use it in manifest

   <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" />
Atif AbbAsi
  • 5,633
  • 7
  • 26
  • 47