How to set Android toolbar height?
Asked Answered
M

3

12

I want to achieve this:

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.

Relevant Code

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>

And this function in the 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);
    }
Meenen answered 26/6, 2015 at 22:2 Comment(1)
You are using the ActionBar. Where is your Toolbar code? You can set the height here android:minHeight="?attr/actionBarSize" in your XML. Use height and not minHeight.Deneendenegation
H
22
<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

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

give it a prefered height android:layout_height="200dp"

Henotheism answered 27/6, 2015 at 1:27 Comment(0)
R
0

Use some theme with no action bar for this activity or the whole app if you don't need action bar's functionality (like Theme.Holo.NoActionBar). You can add layout of your top bar directly in activities root layout. If you will use it in other activities then consider making separate xml files for layout or even your own ActionBarView class.

Retinoscopy answered 26/6, 2015 at 23:55 Comment(0)
B
0

you can use AppBarLayout like this :


<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar_"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tabs"
            app:tabBackground="@color/White"
            app:tabIndicatorColor="@color/OrangeFFC200"
            app:tabTextAppearance="@style/MineCustomTabText">

        </android.support.design.widget.TabLayout>

</android.support.design.widget.AppBarLayout>

Behest answered 20/2, 2019 at 23:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.