如何设置Android工具栏高度? [英] How to set Android toolbar height?

查看:122
本文介绍了如何设置Android工具栏高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现这一目标:

我想做的是制作一个具有更高高度的自定义工具栏,并正常使用tabhost和tabpager.我已经实现了它,但是工具栏显示的是正常高度,因此它并没有显示出我想要的高度,只是顶部.这是正确的方法还是可以在线性/相对布局下面设置TabHost?因为我不需要将其用作操作栏.

What I thought was to make a Custom Toolbar with a bigger height and work with the tabhost and tabpager normally. I have implemented it, but the toolbar is showing the normal height, so it doesn't show as I want, just the top part. Is this the right approach or is it possible to set a TabHost below a Linear/Relative Layout? Because I don't need to work with it as an action bar.

相关代码

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);
    }

推荐答案

<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

您的ToolBarViewGroup,它的高度环绕其子级,这意味着只有对子级进行测量后,它的大小才会固定.您的最小身高在5060 dip左右,这就是您的ToolBar的最低高度. 因此,如果您的孩子的身高未加到一个合理的大数字,则仍为<= 50

your ToolBar which is a ViewGroup is wraping its height around its children meaning it will get a fixed size only if the children are measured. your minimum height is around 50 to 60 dip, that is how low your ToolBar will be. so if your children height do not add up to a reasonable big number it will still be <= 50

给它一个首选的高度android:layout_height="200dp"

这篇关于如何设置Android工具栏高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆