Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add button dynamically ? #42

Open
ismailtosun opened this issue Oct 12, 2020 · 2 comments
Open

how to add button dynamically ? #42

ismailtosun opened this issue Oct 12, 2020 · 2 comments

Comments

@ismailtosun
Copy link

No description provided.

@bahaahany2019
Copy link

bahaahany2019 commented Oct 14, 2020

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
Copy link
Owner

Is this resolved for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants