我要实现这一点:如何设置Android工具栏高度?
我的想法是做一个自定义工具栏有一个更大的高度,并与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>
而且在活动这个功能:
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'。 “工具栏”代码在哪里?你可以在你的XML中设置高度'android:minHeight =“?attr/actionBarSize”'。使用高度而不是minHeight。 –