【发布时间】:2015-06-26 22:02:40
【问题描述】:
我想实现这个:
我的想法是制作一个高度更大的自定义工具栏,并正常使用 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);
}
【问题讨论】:
-
您使用的是
ActionBar。你的Toolbar代码在哪里?您可以在您的 XML 中设置高度android:minHeight="?attr/actionBarSize"。使用高度而不是 minHeight。
标签: android android-actionbar android-tabhost android-toolbar