Holo主题让我的按钮更大

Joh*_*y19 4 layout android button

在api> =版本11的设备上应用holo主题时我有点担心我的自定义按钮变大(高度,宽度似乎相同)

这是没有全息的 在此输入图像描述

这是他们的全息 在此输入图像描述

有人能告诉我是什么原因造成的吗?如果没有holo主题可以保持相同的按钮大小?

ps:这是我的按钮形状:

<?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>
Run Code Online (Sandbox Code Playgroud)

这就是我在我的按钮上应用它的方式(即线性水平线性布局,重量为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" />
Run Code Online (Sandbox Code Playgroud)

谢谢!!

Ale*_*xis 11

Android的全息主题设置了minWidth,并在了minHeight为Holo.Widget.Button系统styles.xml资源指定除了那些由非全息按钮,Widget.Button使用的规则.即使使用小按钮标题,该按钮也会在Android 4.2中占用64x48dip.

<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" />
Run Code Online (Sandbox Code Playgroud)


小智 6

  1. 制作以下xml文件

  2. 您可以在清单中应用自定义主题

喜欢这个 - android:theme ="@ style/NoActionBar"

[在values文件夹中]

<?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>
Run Code Online (Sandbox Code Playgroud)

[在values-v11文件夹中]

<?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>
Run Code Online (Sandbox Code Playgroud)