【发布时间】:2015-09-06 20:30:05
【问题描述】:
我正在为 android(我的第一个应用程序)做一个简单的计算器应用程序,当我尝试将特定的 android:theme 应用于按钮时,我遇到了一些问题。
当具有特定主题的按钮尝试在onclick事件中执行活动方法时,问题就出现了。根据我在 StackOverflow 中搜索的内容,就像具有特定主题的按钮的“上下文”与活动上下文不同,因此它找不到我处理活动中写入的 onclick 的方法。
我在 style.xml 中定义了我的应用程序主题和我的特定按钮主题:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorButtonNormal">#dc000000</item>
<item name="android:background">#dc262626</item>
<!-- Customize your theme here. -->
</style>
<style name="contextButtonTheme" parent="AppTheme">
<item name="colorButtonNormal">@color/contextButtonsColor</item>
</style>
</resources>
布局xml中有我的按钮:
<Button
android:layout_width="0dp"
android:layout_weight="25"
android:layout_height="match_parent"
android:text="X"
android:id="@+id/multButton"
android:textSize="11pt"
android:theme="@style/contextButtonTheme"
android:onClick="onClickButton"/>
我在这里读到的解决方案是将“android:theme”更改为“style”,虽然这解决了崩溃,但不应用 colorButtonNormal 新颜色:(。
请帮帮我D:
PD:对不起我的英语不好
【问题讨论】: