我想实现这个目标:
我想的是制作一个更高的自定义工具栏,并正常使用tabhost和tabpager。我已经实现了它,但是工具栏显示的是正常高度,所以它没有显示我想要的,只是顶部。这是正确的方法还是可以将TabHost设置为线性/相对布局?因为我不需要将它作为动作栏使用它。
相关守则
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbarTitle"
android:orientation="vertical"
android:background="@color/black"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:theme="@style/AppTheme"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="55dp"
android:scaleType="centerInside"
android:src="@drawable/logo_home"
/>
<TextView
android:id="@+id/txt_version"
android:text="@string/app_version"
android:textColor="@color/white"
android:layout_below="@+id/img_logo"
android:paddingBottom="10dp"
android:paddingTop="15dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
而这个功能在Activity中:
private void setupActionBar()
{
ActionBar ab = getSupportActionBar();
ab.setDisplayShowCustomEnabled(true);
ab.setDisplayShowTitleEnabled(false);
LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.toolbar_title, null);
ab.setCustomView(v);
}
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbarTitle"
android:orientation="vertical"
android:background="@color/black"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize" //pay attention here
android:theme="@style/AppTheme"
android:layout_height="wrap_content"> //pay attention here
你的ToolBar
是一个ViewGroup
围绕它的孩子的高度,这意味着它只有在孩子被测量时才会得到一个固定的大小。你的最小高度是50
到60
dip
,这就是你的ToolBar
有多低。因此,如果你的孩子身高不合理的大数字,它仍然是<= 50
给它一个首选的高度qazxsw poi
如果您不需要操作栏的功能(如android:layout_height="200dp"
),请为此活动使用一些没有操作栏的主题或整个应用程序。您可以直接在活动根布局中添加顶栏的布局。如果您将在其他活动中使用它,那么考虑为布局或甚至您自己的ActionBarView类创建单独的xml文件。
你可以像这样使用AppBarLayout:
Theme.Holo.NoActionBar