0

I am developing an Android application that has an action bar. I know how to set height of action bar in pixels, but I would like to set action bar's height to be 15% of screen's height. Is that possible? Here is what I have so far in my resources file:

<!-- Application theme. -->
<style name="CustomActionBarTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

</style>

<style name="Widget.Styled.ActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:displayOptions">showHome|useLogo</item>
    <item name="android:background">@color/white</item>
    <item name="android:height">90dp</item>
</style>
4
  • 1
    You can't do that with XML alone. You may be able to do it by writing a custom view.
    – Karakuri
    Feb 12, 2015 at 7:33
  • 1
    Use toolbar instead,,,,,
    – IshRoid
    Feb 12, 2015 at 8:30
  • @Ishrat - I believe toolbars would only work with the latest Android API, and I don't want to limit my app like that, though it could be a good solution. Feb 12, 2015 at 12:07
  • @user3623874 : No Toolbar is available for all previous version also, Please look at my answer below.
    – IshRoid
    Feb 13, 2015 at 5:17

1 Answer 1

0

You can use below code, to set custom height of ActionBar,

Compatible toolbar for previous versions of Android,Custom height is set in my case i set 100dp instead of 48dp default.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="100dp"
        android:background="#e5e5e5"
        android:popupTheme="@android:style/ThemeOverlay.Material.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:layout_alignParentTop="true"/>

<-- Your other component or xml code goes here...!-->

</LinearLayout >

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.