【问题标题】:Holo theme make my button biggerHolo 主题让我的按钮变大
【发布时间】:2013-05-04 05:42:18
【问题描述】:

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

这是没有全息的

这是全息他们

谁能告诉我这是什么原因造成的?如果可以保持与没有全息主题相同的按钮大小?

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>

这就是我在按钮上应用它的方式(即在权重为 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" />

谢谢!!

【问题讨论】:

    标签: android button layout


    【解决方案1】:

    Android 的 Holo 主题在系统 styles.xml 资源中为 Holo.Widget.Button 设置了 minWidth 和 minHeight,它指定了除非 Holo 按钮 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" />
    

    【讨论】:

      【解决方案2】:
      1. 制作下面的xml文件

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

      像这样 - android:theme="@style/NoActionBar"

      [在值文件夹中]

      <?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>
      

      [在 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多