Appcompat-v7: Custom view not aligned correctly in ActionBar

I am trying to use an ActionBar based on the Appompat toolbar

Here is my toolbar.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="bottom" android:paddingBottom="0dp" android:background="?attr/colorPrimaryDark"> </android.support.v7.widget.Toolbar> 

I am including this in my activity.xml file. And then in my Activity OnCreate method, I set a custom PagerStrip in an ActionBar

  ActionBar actionBar = getSupportActionBar(); actionBar.setCustomView(R.layout.pager_strip); actionBar.setDisplayShowCustomEnabled(true); tabs = (PagerSlidingTabStrip) actionBar.getCustomView().findViewById(R.id.tabs_strip); tabs.setViewPager(mPager); 

Under my PagerStrip in ActionBar there is a lining. I want to remove this add-on. here is a photo showing the problem. enter image description here

This works great with ActionBarSherlock

+7
android android-activity appcompat
source share
2 answers

I had a similar problem: I moved to the toolbar template:

 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" app:theme="@style/ThemeOverlay.AppCompat.ActionBar"> <my.custom.widget.class android:id="@+id/tab_bar" android:layout_width="match_parent" android:layout_height="match_parent"> </my.custom.widget.class> </android.support.v7.widget.Toolbar> 

but AppCompat gave me a weird addition around my user view: enter image description here

My fix:

Add app:contentInsetStart="0dp" and app:contentInsetEnd="0dp" to the toolbar attributes; and android:minHeight="?attr/actionBarSize" to the widget custom attributes.

Result:
enter image description here

Not sure if the solution follows material design guidelines, but hope this helps someone.

+11
source share

A toolbar is a replacement widget for an Actionbar in some cases. If you want to use the toolbar, you can try:

 Toolbar=(Toolbar)findViewbyId(R.id.toolbar); setSupportActionbar(toolbar); 

I used the toolbar in DrawerLayout. You can always find a toolbar in my navigation box.

P / S: use toolbar in ActionBarActivity

-3
source share

All Articles