user7232539
user7232539

Reputation:

How to make Android toolbar shorter in terms of height

I'd like to make toolbar height relatively small. I tried to set minHeight but it doesn't work.

Thin green line is what I'd like to have as the toolbar but toolbar ignores minHeight so there's that red part around it.

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar 
        android:id="@+id/WindowTitleBar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:minHeight="0dp"
        android:background="#ff0000"
        app:contentInsetEnd="0dp" app:contentInsetStart="0dp">

            <View 
                android:layout_width="match_parent" 
                android:layout_height="5dp" 
                android:background="#00ff00"/>
    </android.support.v7.widget.Toolbar>

    <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Something" />
</LinearLayout>

public class TActivity extends AppCompatActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.t);

  Toolbar WindowTitleBar = (Toolbar)findViewById(R.id.WindowTitleBar);
  setSupportActionBar(WindowTitleBar);
 }
}

Of course, my toolbar will be more functional but this code illustrate the issue with height.

Note that I know that I could set layout_height to a fixed value but is there any more elegant solution?

Upvotes: 0

Views: 67

Answers (2)

SpiritCrusher
SpiritCrusher

Reputation: 21043

What could possibly can be the solution other than setting height.

Just to clarify the attribute minHeight makes the View be at least this many pixels of height. So that's not gonna work with TooBar.For normal ViewGroup it will work.

So the solution is setting android:layout_height to predefined pixel.

Apart from that this will just just make TooBar useless. I mean a simple View can do that . The whole point of having ToolBar is to achieve material design and having menus and drawer indicator, Back, Title inside it . If you want ToolBar as tall as the green line in your image then i think there is no use of having toolbar . You can simply use a View.

Upvotes: 1

Natan
Natan

Reputation: 1885

I think setting the layout_height would be the best solution for your scenario. Maybe you could extract the toolbar layout to another xml to increase reusability and extract the height to dimens.xml. I can't think of a more elegant solution.

I hope it helps.

Upvotes: 1

Related Questions