Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Holo theme make my button bigger

I have a little concern when applying the holo theme on devices with api >= version 11 My custom buttons get bigger (in height, the width seems to be the same)

This is without holo them enter image description here

this is with holo them enter image description here

May someone tell me what is causing this? and If it is possible to keep the same button size as without holo theme?

ps: this is my button shape:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#F000" />

    <stroke
        android:width="1px"
        android:color="#BB000000" />

    <padding
        android:bottom="7dp"
        android:left="10dp"
        android:right="10dp"
        android:top="7dp" />

    <corners
        android:bottomLeftRadius="5dp"
        android:bottomRightRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp" />

    <gradient
        android:angle="90"
        android:centerColor="#5b5bcd"
        android:endColor="#6f6fcf"
        android:startColor="#4747e0"
        android:type="linear" />

</shape>

and this is how I apply it on my button (that is in a linear hirozontal linearLayout with a weight of 0.8)

<Button
            android:id="@+id/addplayer"
            android:layout_width="0px"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="5dp"
            android:layout_weight="0.8"
            android:background="@drawable/blue_button_selector"
            android:text="Add player" />

thank you!!

like image 273
Johny19 Avatar asked May 09 '13 16:05

Johny19


2 Answers

Android's Holo theme sets a minWidth and minHeight in the system styles.xml resource for Holo.Widget.Button which specifies rules in addition to those used by the non-holo button, Widget.Button. Even with a small button title, the button will take up 64x48dip in Android 4.2.

<Button
    android:id="@+id/sample_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Z"
    android:padding="6dp"
    android:minHeight="1dp"
    android:minWidth="1dp"
    android:layout_marginBottom="6dp"
    android:layout_marginRight="6dp"
    style="@style/CustomButton"
    android:textSize="16sp" />
like image 186
Alexis Avatar answered Sep 23 '22 22:09

Alexis


  1. Make below xml files

  2. You can apply custom theme in the menifest

Like this - android:theme="@style/NoActionBar"

[In the values folder]

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="NoActionBar" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Inherits the default theme for pre-HC (no action bar) -->
    </style>
</resources>

[In the values-v11 folder]

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light.NoActionBar">
    <!-- Inherits the Holo theme with no action bar; no other styles needed. -->
    <item name="android:buttonStyle">@style/CustomHoloLightButtonStyle</item>
</style>


<style name="CustomHoloLightButtonStyle" parent="@android:style/Widget.Holo.Light.Button">
    <item name="android:minHeight">1dip</item>
    <item name="android:minWidth">1dip</item>
</style>    

</resources>
like image 39
user3544280 Avatar answered Sep 22 '22 22:09

user3544280