0

我在将主题应用到按钮时遇到问题。不使用主题一切看起来都很好,正如您在此屏幕截图中看到的那样:http: //i47.tinypic.com/2czyctv.jpg

在我应用我的主题后,它看起来像这样:http: //i48.tinypic.com/w03s6x.png

颜色很好,但是按钮的高度不对,上按钮和水平线之间的空间也消失了。实际上,主题按钮的大小应该看起来像非主题按钮,因为我唯一想要改变的是颜色。

值/主题.xml:

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

<style name="Theme.KIT.Styled" parent="Theme.Sherlock.Light.DarkActionBar">

    <item name="actionBarStyle">@style/ActionBar</item>
    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="android:buttonStyle">@style/Button</item>

</style>

<style name="ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="background">@drawable/actionbar_background_shape</item>
    <item name="android:background">@drawable/actionbar_background_shape</item>
</style>

<style name="Button" parent="@android:style/Widget.Button">
    <item name="android:background">@drawable/kit_button</item>
</style>
</resources>

可绘制/kit_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_enabled="false"
    android:drawable="@drawable/kit_button_background_shape" />
<item
    android:state_pressed="true"
    android:state_enabled="true"
    android:drawable="@drawable/kit_button_background_shape" />
<item
    android:state_focused="true"
    android:state_enabled="true"
    android:drawable="@drawable/kit_button_background_shape" />
<item
    android:state_enabled="true"
    android:drawable="@drawable/kit_button_background_shape" />
</selector>

可绘制/kit_button_background_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient 
    android:startColor="@color/KIT_GREEN"
    android:endColor="@color/KIT_GREEN_LIGHT"
    android:angle="90"
    android:centerX="0.5"
    android:centerY="0.5" />
</shape>

我希望这样可以帮助我。对不起我的英语不好...

4

1 回答 1

0

您的按钮填充曾经在 9-patch 背景中声明, GradientDrawable 不会为您执行此操作。您需要为您的主题添加一个 android:padding 属性或使用 9-patch。

于 2012-08-10T16:59:33.727 回答