我已经在这个应用程序上工作了一段时间,而且android没有问题:onClick与活动中的相关方法相关联。
...然后我开始搞乱主题,如果我用'android:theme =“@ style / CheckBoxTheme”'将主题直接应用于他们,我的CheckBox onClick开始破坏了,调整一下: java.lang.IllegalStateException:在活动类android.view.ContextThemeWrapper中找不到onLinkCheckThemeWrapper的方法onViewCheckThemeWrapper视图类android.support.v7.widget.AppCompatCheckBox,id为'chx_sub_all'
如果我不在checkBoxes上使用android:theme而只是让RF_AppTheme做它的事情,我可以用android:buttonTint改变复选框就好了。 onClicks工作没问题。 (之所以我将它分成它自己的特定主题是因为我想支持一个较低的版本,所以我有一个'value / styles.xml'只改变了背景颜色,并且'value-r21 /styles.xml'使用版本21+的buttonTint)
据我所知,正在使用的主题是更改CheckBox的版本,因此它会尝试查看不是我的MainActivity的活动,该活动不存在。
我的主题实际上是项目生成的主题的复制/粘贴,添加了更多内容:
<resources>
<style name="RF_AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">@color/colorBackground</item>
<item name="android:textSize">@dimen/text_size</item>
<item name="android:textColor">@color/colorTextNormal</item>
<item name="android:buttonTint">@color/colorPrimaryLight</item>
</style>
<style name="CheckBoxTheme" parent="RF_AppTheme">
<item name="android:buttonTint">@color/colorPrimaryLight</item>
<item name="android:gravity">center_vertical</item>
</style>
</resources>
这是我的MainActivity的概念,没有复制/粘贴所有其他代码。
public class MainActivity extends AppCompatActivity {
//onStart and the like above
public void onLinkCheckboxClicked(View view)
{
//doing checkbox things here, which never gets called
}
}
这是我的复选框之一
<CheckBox android:id="@+id/chx_sub_all"
android:theme="@style/CheckBoxTheme"
android:text="@string/check_all"
android:textColor="@color/colorTextNormal"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onLinkCheckboxClicked"/>