0

Hello I wanted to add custom ActionBar to my application in Android using this method:

   LinearLayout ll_q = (LinearLayout) findViewById(R.id.qtitlebar);
   getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
   getSupportActionBar().setCustomView(R.layout.question_titlebar);

The result is:

How to get rid of the grey area in this ActionBar and the menu button?

adneal
  • 30,484
  • 10
  • 122
  • 151
John
  • 157
  • 9

3 Answers3

1

The solution is adding :

actionBar.setDisplayShowTitleEnabled(false);

The code should look something like:

actionBar = getSupportActionBar(); 
actionBar.setDisplayShowHomeEnabled(false); 
actionBar.setDisplayShowCustomEnabled(true); 
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setCustomView(R.layout.actionbar);//set the custom view

in style file add below code :

<item name="toolbarStyle">@style/Widget.Toolbar</item>


<style name="Widget.Toolbar" parent="@style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
</style>
Darshan Mistry
  • 3,294
  • 1
  • 19
  • 29
1

You should set Layout as well for Custom ActionBar i.e.

Inflate custom actionbar view

LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v =inflator.inflate(R.layout.actionbar_discard_done, null);

then set custom view with layout param

ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
 getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
 getSupportActionBar().setCustomView(v,params);
Mukesh Kumar Singh
  • 4,512
  • 2
  • 22
  • 30
0

If You are using Android Studio do the following:

  1. Extend your class with Activity instead of ActionBarActivity.
  2. Open your app's Manifest File and change

        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 
    
Saurabh
  • 62
  • 1
  • 15