Java Code Examples for android.widget.RadioButton#setTextSize()

The following examples show how to use android.widget.RadioButton#setTextSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlatTabGroup.java    From support with Apache License 2.0 7 votes vote down vote up
private void generateTabView(Context context, AttributeSet attrs) {
    if (mItemString == null) {
        return;
    }
    mTabViewIds = new int[mItemString.length];
    int i = 0;
    for (String text : mItemString) {
        RadioButton button = new RadioButton(context, attrs);
        button.setGravity(Gravity.CENTER);
        button.setButtonDrawable(android.R.color.transparent);
        button.setText(text);
        button.setTextColor(mTextColor);
        button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
        int id = generateViewId();
        button.setId(mTabViewIds[i++] = id);
        addView(button, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1));
    }
}
 
Example 2
Source File: RecyclerViewScrollActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
private void initTab() {
    int padding = Tools.dip2px(this, 10);
    for (int i = 0; i < 20; i++) {
        RadioButton rb = new RadioButton(this);
        rb.setPadding(padding, 0, padding, 0);
        rb.setButtonDrawable(null);
        rb.setGravity(Gravity.CENTER);
        rb.setTag(i * 5);
        rb.setText("Group " + i);
        rb.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
        try {
            rb.setTextColor(getResources().getColorStateList(R.color.bg_tab_text));
        } catch (Exception e) {
            e.printStackTrace();
        }
        rb.setCompoundDrawablesWithIntrinsicBounds(null, null, null, getResources().getDrawable(R.drawable.bg_block_tab));
        rb.setOnCheckedChangeListener(onCheckedChangeListener);
        rg_tab.addView(rb);
    }
    ((RadioButton) rg_tab.getChildAt(0)).setChecked(true);
}
 
Example 3
Source File: LanguageFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.intro_language, container, false);
    RadioGroup radioGroup = v.findViewById(R.id.radioGroup);
    
    List<LocaleUtils.Translation> langs = LocaleUtils.getSupportedLanguages(getActivity());
    String currentLang = Preferences.LANGUAGE.get();
    int pos = 0;
    for (int i = 0; i < langs.size(); i++) {
        LocaleUtils.Translation lang = langs.get(i);
        if (lang.getLanguage().equals(currentLang))
            pos = i + 1;
        RadioButton button = new RadioButton(getContext());
        button.setTag(lang.getLanguage());
        button.setText(lang.getDisplayText());
        button.setTextColor(getResources().getColor(R.color.white));
        button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        int padding = (int) (button.getTextSize() / 2);
        button.setPadding(padding, padding, padding, padding);
        button.setOnCheckedChangeListener(this);
        radioGroup.addView(button);
    }
    if (pos != 0)
        ((RadioButton) radioGroup.getChildAt(pos)).setChecked(true);
    return v;
}
 
Example 4
Source File: LiveRegionFragment.java    From android-accessibility with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Toolbar toolbar = view.findViewById(R.id.toolbar);
    ((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);

    List<String> androidVersions = new ArrayList<>(Arrays.asList(getResources().getStringArray(
            R.array.android_versions)));
    final int correctAnswerIndex = androidVersions.indexOf(getString(R.string.lollipop));
    final RadioGroup radioGroup = view.findViewById(R.id.radio_group);
    mFeedbackTextView = view.findViewById(R.id.feedback_text_view);

    if (radioGroup != null && correctAnswerIndex != -1) {
        for (int i = 0; i < androidVersions.size(); i++) {
            RadioButton radioButton = new RadioButton(getContext());
            radioButton.setText(androidVersions.get(i));
            radioButton.setId(i);
            radioButton.setPadding(36, 36, 36, 36 );
            radioButton.setTextSize(18f);
            radioGroup.addView(radioButton);
        }

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int indexOfCheckedChild = radioGroup.indexOfChild(view.findViewById(checkedId));
                if (indexOfCheckedChild == correctAnswerIndex) {
                    mFeedbackTextView.setText(R.string.correct);
                    mFeedbackTextView.setBackgroundColor(ContextCompat.getColor(requireContext(),
                            R.color.green));
                } else {
                    mFeedbackTextView.setText(R.string.incorrect);
                    mFeedbackTextView.setBackgroundColor(ContextCompat.getColor(requireContext(),
                            R.color.red));
                }
            }
        });
    }
}
 
Example 5
Source File: LanguageFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.intro_language, container, false);
    RadioGroup radioGroup = v.findViewById(R.id.radioGroup);
    
    List<LocaleUtils.Translation> langs = LocaleUtils.getSupportedLanguages(getActivity());
    String currentLang = Preferences.LANGUAGE.get();
    int pos = 0;
    for (int i = 0; i < langs.size(); i++) {
        LocaleUtils.Translation lang = langs.get(i);
        if (lang.getLanguage().equals(currentLang))
            pos = i + 1;
        RadioButton button = new RadioButton(getContext());
        button.setTag(lang.getLanguage());
        button.setText(lang.getDisplayText());
        button.setTextColor(getResources().getColor(R.color.white));
        button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        int padding = (int) (button.getTextSize() / 2);
        button.setPadding(padding, padding, padding, padding);
        button.setOnCheckedChangeListener(this);
        radioGroup.addView(button);
    }
    if (pos != 0)
        ((RadioButton) radioGroup.getChildAt(pos)).setChecked(true);
    return v;
}
 
Example 6
Source File: SwitchButton.java    From SwitchButton with Apache License 2.0 5 votes vote down vote up
private RadioButton createRadioView() {
	RadioButton mRadioButton = new RadioButton(getContext(), null, mRadioStyle > 0 ? mRadioStyle : android.R.attr.radioButtonStyle);
	if (mRadioStyle == 0) {
		mRadioButton.setGravity(Gravity.CENTER);
		mRadioButton.setEllipsize(TruncateAt.END);
	}
	if (mTextColor != null)
		mRadioButton.setTextColor(mTextColor);
	if (textSize > 0)
		mRadioButton.setTextSize(textSize);
	return mRadioButton;
}
 
Example 7
Source File: SelectOneWidget.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public SelectOneWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    int padding = (int)Math.floor(context.getResources().getDimension(R.dimen.select_padding));

    mItems = getSelectChoices();
    buttons = new Vector<>();

    String s = null;
    if (prompt.getAnswerValue() != null) {
        s = prompt.getAnswerValue().uncast().getString();
    }

    //Is this safe enough from collisions?
    buttonIdBase = Math.abs(prompt.getIndex().hashCode());

    if (mItems != null) {
        for (int i = 0; i < mItems.size(); i++) {
            final RadioButton rb = new RadioButton(getContext());
            String markdownText = prompt.getSelectItemMarkdownText(mItems.get(i));
            if (markdownText != null) {
                rb.setText(forceMarkdown(markdownText));
            } else {
                rb.setText(prompt.getSelectChoiceText(mItems.get(i)));
            }
            rb.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize);
            rb.setId(i + buttonIdBase);
            rb.setEnabled(!prompt.isReadOnly());
            rb.setFocusable(!prompt.isReadOnly());

            rb.setBackgroundResource(R.drawable.selector_button_press);

            buttons.add(rb);

            if (mItems.get(i).getValue().equals(s)) {
                rb.setChecked(true);
            }

            //Move to be below the above setters. Not sure if that will cause
            //problems, but I don't think it should.
            rb.setOnCheckedChangeListener(this);

            String audioURI =
                    prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                            FormEntryCaption.TEXT_FORM_AUDIO);

            String imageURI =
                    prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                            FormEntryCaption.TEXT_FORM_IMAGE);

            String videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video");

            String bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image");

            MediaLayout mediaLayout = MediaLayout.buildAudioImageVisualLayout(getContext(), rb, audioURI, imageURI, videoURI, bigImageURI);
            mediaLayout.setPadding(0, padding, 0, padding);
            mediaLayout.setEnabled(!mPrompt.isReadOnly());
            mediaLayout.setOnClickListener(v -> rb.performClick());
            addView(mediaLayout);


            // Last, add the dividing line (except for the last element)
            ImageView divider = new ImageView(getContext());
            divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            if (i != mItems.size() - 1) {
                addView(divider);
            }
        }
        addClearButton(context, s != null && !prompt.isReadOnly());
    }
}
 
Example 8
Source File: SelectOneAutoAdvanceWidget.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public SelectOneAutoAdvanceWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    LayoutInflater inflater = LayoutInflater.from(getContext());

    mItems = getSelectChoices();
    buttons = new Vector<>();
    listener = (AdvanceToNextListener)context;

    String s = null;
    if (prompt.getAnswerValue() != null) {
        s = ((Selection)prompt.getAnswerValue().getValue()).getValue();
    }

    //Is this safe enough from collisions?
    buttonIdBase = Math.abs(prompt.getIndex().hashCode());

    if (mItems != null) {
        for (int i = 0; i < mItems.size(); i++) {

            RelativeLayout thisParentLayout =
                    (RelativeLayout)inflater.inflate(R.layout.quick_select_layout, null);

            final LinearLayout questionLayout = (LinearLayout)thisParentLayout.getChildAt(0);
            ImageView rightArrow = (ImageView)thisParentLayout.getChildAt(1);

            final RadioButton r = new RadioButton(getContext());
            r.setOnCheckedChangeListener(this);
            String markdownText = prompt.getSelectItemMarkdownText(mItems.get(i));
            if (markdownText != null) {
                r.setText(forceMarkdown(markdownText));
            } else {
                r.setText(prompt.getSelectChoiceText(mItems.get(i)));
            }
            r.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mQuestionFontSize);
            r.setId(i + buttonIdBase);
            r.setEnabled(!prompt.isReadOnly());
            r.setFocusable(!prompt.isReadOnly());

            Drawable image = getResources().getDrawable(R.drawable.icon_auto_advance_arrow);
            rightArrow.setImageDrawable(image);
            rightArrow.setOnTouchListener((v, event) -> {
                r.onTouchEvent(event);
                return false;
            });

            buttons.add(r);

            if (mItems.get(i).getValue().equals(s)) {
                r.setChecked(true);
            }

            String audioURI = null;
            audioURI =
                    prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                            FormEntryCaption.TEXT_FORM_AUDIO);

            String imageURI = null;
            imageURI =
                    prompt.getSpecialFormSelectChoiceText(mItems.get(i),
                            FormEntryCaption.TEXT_FORM_IMAGE);

            String videoURI = null;
            videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video");

            String bigImageURI = null;
            bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image");

            MediaLayout mediaLayout = MediaLayout.buildAudioImageVisualLayout(getContext(), r, audioURI, imageURI, videoURI, bigImageURI);

            questionLayout.addView(mediaLayout);

            // Last, add the dividing line (except for the last element)
            ImageView divider = new ImageView(getContext());
            divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            if (i != mItems.size() - 1) {
                mediaLayout.addDivider(divider);
            }

            addView(thisParentLayout);
        }
    }
}