【发布时间】:2014-04-04 20:34:55
【问题描述】:
我正在设置应用程序中所有按钮的默认外观,如下所示。当我这样做时,即使我已经正确定义了所有功能,单击按钮也不会发生任何事情。事实上,当我注释掉<item name="android:buttonStyle">@style/button</item> 行时,按钮点击工作正常(当然,它们使用默认的android 样式)。应用程序主题也在清单中定义:android:theme="@style/AppTheme"
有人可以告诉我为什么会这样吗?谢谢。
res/drawable 中的button_shape.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:radius="10dp" />
<gradient
android:angle="90"
android:startColor="#6AA4ED"
android:endColor="#927BED"/>
<padding
android:left="10dp"
android:right="10dp"
android:top="12dp"
android:bottom="12dp" />
</shape>
styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:buttonStyle">@style/button</item>
</style>
<style name="button">
<item name="android:background">@drawable/button_shape</item>
</style>
【问题讨论】:
-
为什么不将样式应用为按钮本身的背景,看看它是否有效:)
-
当我使用 android:background="@drawable/button_shape" 作为按钮时,它工作正常。但我想对所有按钮都这样做,而不必把这条线放在任何地方。为什么会发生这种情况??
-
你是添加点击监听还是在xml中定义点击方法?
-
XML。使用 android:onClick。是这个问题吗?
标签: android android-button android-drawable android-styles