Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styles, minHeight/maxHeight: I cannot get the maxHeight to override the theme minHeight

Tags:

android

Im thinking that more "global" styles are always overridden by more "local" Styles. For example, if I redefine all Buttons to have textSize=40dip (apply that Style as a Theme for the Application) and then apply another Style to a specific Button that says textSize=10dip, then that specific Button should get 10dip textSize.

And that is how it works, usually. But not when it comes to maxHeight. Here is the scenario:

In my styles.xml I have one Style where I inherit the default Button and change textSize and minHeight, and then another Style that sets some other values (but also inherits from Button), like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Button" parent="@android:style/Widget.Button">
    <item name="android:textSize">26dip</item>
    <item name="android:minHeight">60dip</item>
</style>

<style name="ButtonHeader" parent="@android:style/Widget.Button">
    <item name="android:textSize">18dip</item>
    <item name="android:minWidth">70dip</item>
    <item name="android:maxHeight">10dip</item>
</style>
</resources>    

I apply the first Style as a theme for my Activity which makes all the buttons larger (minHeight=60dip). But I have a "header" (where I have some other buttons) that I do not want to have a minHeight of 60dip, and for those buttons I want to use the ButtonHeader, setting the maxHeight to 10dip.

In my header.xml it looks like this:

<Button style="@style/ButtonHeader" android:text="UPP" android:id="@+id/Header_Button_UPP" android:layout_width="wrap_content" android:layout_height="wrap_content" ></Button>
<Button style="@style/ButtonHeader" android:text="ALT" android:id="@+id/Header_Button_ALT" android:layout_width="wrap_content" android:layout_height="wrap_content" ></Button>
<Button style="@style/ButtonHeader" android:text="NAV" android:id="@+id/Header_Button_NAV" android:layout_width="wrap_content" android:layout_height="wrap_content" ></Button>
<Button style="@style/ButtonHeader" android:text="HIS" android:id="@+id/Header_Button_HIS" android:layout_width="wrap_content" android:layout_height="wrap_content" ></Button>

I am specificly styling the buttons, overriding the "global" theme. It works in some parts; the textSize for these header-buttons is correctly set to 18dip, but the maxHeight is ignored - these buttons also increase in height to 60dip.

If I, in the style for ButtonHeader, set android:minHeight="100dip" the buttons in the header will increase in size to 100dip, overriding the Theme. But, as stated above, when I have android:maxHeight instead, nothing happens.

What am I missing?

like image 988
Ted Avatar asked Jan 07 '10 01:01

Ted


1 Answers

Shouldn't your ButtonHeader style override the minHeight property? It seems like you end up with minHeight=60dp and maxHeight=10dp, and minHeight wins. If you explictly set the minHeight to something else, you shouldn't have that problem.

like image 80
Cheryl Simon Avatar answered Nov 15 '22 07:11

Cheryl Simon