所以我正在努力解决我的RadioButtons问题,这两个API> 21和API< 21.我似乎无法找到明确的答案。我以编程方式创建RadioButtons:
public void addRadioButtonsWithFirebaseAnswers(DataSnapshot dataSnapshot, int numberOfAnswers) {
mPollAnswerArrayList = new ArrayList<AppCompatRadioButton>();
for (int i = (numberOfAnswers - 1); i >= 0; i--) {
Log.e("Number of Answers", "The number of answers is " + numberOfAnswers);
int indexCreated = ((numberOfAnswers-1)-i);
mPollAnswerArrayList.add((indexCreated), new AppCompatRadioButton((getActivity().getApplicationContext()),null,R.style.RadioButtonTeal));
mPollAnswerArrayList.get(indexCreated).setId(indexCreated);
String firebaseChild = String.valueOf(indexCreated+1);
mPollAnswerArrayList.get(indexCreated).setText(dataSnapshot.child(POLL_ANSWERS_LABEL).child(firebaseChild).child("Answer").getValue().toString());
mPollAnswerArrayList.get(indexCreated).setTextColor(getResources().getColor(R.color.black));
mPollAnswerArrayList.get(indexCreated).setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.radio_button_answer_text_size));
if (Build.VERSION.SDK_INT >= 21) {
mPollAnswerArrayList.get(indexCreated).setButtonTintMode(PorterDuff.Mode.DARKEN);
}
mPollAnswerArrayList.get(indexCreated).setSupportButtonTintList(
ContextCompat.getColorStateList(getActivity(),
R.drawable.single_choice_state_list));
mParams.setMargins((int) getResources().getDimension(R.dimen.radio_question_margin_left), 0, 0, (int) getResources().getDimension(R.dimen.radio_question_margin_bottom));
//// radioButton.setBackgroundColor(getResources().getColor(R.color.actionRed));
mPollQuestionRadioGroup.addView(mPollAnswerArrayList.get(indexCreated), mParams);
}
}
以下是我的主题:
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColor">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
<item name="colorControlActivated">@android:color/holo_red_light</item>
<item name="colorControlNormal">@android:color/black</item>
</style>
<style name="RadioButtonTeal" parent="AppTheme.NoActionBar">
<item name="colorAccent">@color/black</item>
<item name="colorPrimary">@color/black</item>
</style>