5
我为我的按钮的背景制作了一个自定义9贴图片。按钮位于drawable-hdpi和drawable-mdpi文件夹中。我为我的按钮状态创建了自定义选择器文件。为什么我的自定义按钮状态不起作用?
选择文件login_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Image display in background in select state -->
<item android:state_pressed="true" android:drawable="@drawable/login_button_down" />
<!-- Image display in background in select state -->
<item android:state_focused="true" android:drawable="@drawable/login_button_down" />
<!-- Default state -->
<item android:drawable="@drawable/login_button" />
</selector>
然后,我做出的按钮样式定制styles.xml文件:
<style name="login_button_style" parent="@android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FF000000</item>
<item name="android:shadowColor">#FFFFFFFF</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">13dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">@drawable/login_button</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
然后在应用的themes.xml这种风格我的主题文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="@android:style/Theme.NoTitleBar" >
<item name="android:editTextStyle">@style/login_edittext_style</item>
<item name="android:buttonStyle">@style/login_button_style</item>
<item name="android:textViewStyle">@style/login_textview_style</item>
</style>
</resources>
最后将按钮本身添加到布局文件中:
<Button
android:text="@string/login_text"
android:id="@+id/buttonSignIn"
android:layout_width="130dp"
android:layout_height="wrap_content">
</Button>
但是,如果我点击按钮,那么背景图像不会改变。代码是好的,所有编译都很好。我知道我对于两种不同的状态有相同的图像,但即使对于模拟器中的一个状态它也不起作用。任何人都可以指出我的问题在哪里?
编辑:
显然正常状态下工作,因为它得到它从选择XML文件中的图像。现在我想知道为什么其他州不是...
如果将'login_button'为'机器人:background'操作呢? – Macarse 2011-04-04 20:12:27
@Macarse No.添加到按钮android:background =“@ drawable/login_button”,甚至尝试在themes.xml中注释掉按钮样式 - 结果为0. – evilone 2011-04-04 20:18:45
这是一种风格还是主题?你如何将它应用到你的按钮或你的活动? – 2011-04-04 20:46:59