I am making a simple calculator for android (my first application) and I have problems that puzzle over when I try to apply a specific android: theme to a button.
The problem occurs when a button with a certain theme tries to execute an activity method in an onclick event. Based on what I searched in StackOverflow, it looks like the "context" of a button with a specific theme is different from the activity context, and because of this, it cannot find my method that processes the onclick recorded in the action.
There is my style.xml where I define the application theme and my specific button theme:
<resources> <style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> <item name="colorButtonNormal">#dc000000</item> <item name="android:background">#dc262626</item> </style> <style name="contextButtonTheme" parent="AppTheme"> <item name="colorButtonNormal">@color/contextButtonsColor</item> </style> </resources>
There is my button in the xml layout:
<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"/>
The solution I read here is the change to “android: theme” with “style”, although this solves the problem, the new color colorButtonNormal does not apply: (.
Help me D:
PD: Sorry for my bad English
source share