addisonElliott / SegmentedButton

Segmented Control/Button with animation for Android API 16+
Apache License 2.0
148 stars 39 forks source link

how to add button dynamically ? #42

Open ismailtosun opened 3 years ago

bahaahany2019 commented 3 years ago
public void AddSegments(int bookID, int chapterNum) {
        SegmentedButton yesButton = new SegmentedButton(this);
        yesButton.setText(bookListShortAbb[bookID - 1] + " " + chapterNum);
        yesButton.setPadding((int) dpToPx(5), (int) dpToPx(5), (int) dpToPx(5), (int) dpToPx(5));
        yesButton.setLayoutParams(new LinearLayout.LayoutParams(0, 60, 1));
        yesButton.setTextColor(Color.BLACK);
        yesButton.setTextSize(spToPx(20));
        segmentedButtonGroup.addView(yesButton);
    }
 private float dpToPx(float dp) {
        return dp * getResources().getDisplayMetrics().density;
    }

    private float pxToDp(float px) {
        return px / getResources().getDisplayMetrics().density;
    }

    private float spToPx(float sp) {
        return sp * getResources().getDisplayMetrics().scaledDensity;
    }

    private float pxToSp(float px) {
        return px / getResources().getDisplayMetrics().scaledDensity;
    }
addisonElliott commented 3 years ago

Is this resolved for you?