我正在尝试使用基于 Appcompat Toolbar 的 actionBar
这是我的 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>
我将其包含在我的 activity.xml 文件中。 然后在我的 Activity 的 OnCreate 方法中,我将自定义 PagerStrip 设置为 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);
在 ActionBar 中我的 PagerStrip 下面有一些填充。我想删除这个填充。 这是一张显示问题的图片。
这与 ActionBarSherlock 配合得很好
最佳答案
我有一个类似的问题:我已经迁移到工具栏模式:
<?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>
但是 AppCompat 在我的自定义 View 周围给了我一个奇怪的填充:
我的修复:
在Toolbar属性中添加app:contentInsetStart="0dp"
和app:contentInsetEnd="0dp"
;和 android:minHeight="?attr/actionBarSize"
到自定义小部件属性。
结果:
不确定该解决方案是否遵循 Material 设计指南,但希望它能对某人有所帮助。
关于android - appcompat-v7 : Custom view not properly aligned in ActionBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26444753/