Search code examples
androidandroid-studioandroid-seekbar

Change Text Size of all RecyclerView with one SeekBar - Android Studio


I have a recycler view and an ArrayList with a custom adapter. I want to set a SeekBar to change the Text Sizes of all the values in the array at the same time, is this possible? When I use the SeekBar in the activity, it only changes the text size of the first row and thats it. Thanks in advance.

EDIT: code in my main activity:

SeekBar bar = (SeekBar)findViewById(R.id.seekbar);

        bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                TextView Name = findViewById(R.id.aya);

                Name.setTextSize(Float.valueOf(i));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });


Solution

  • Yes you can create a method setTextSizes in adapter and call this method from activity with dynamic seek based of seekbar value.

    Method in adapter

    private int textSize
    
    public void setTextSizes(int textSize) {
        this.textSize = textSize;
        notifyDataSetChanged();
    }
    

    Add this code in onBindViewHolder holder.textview.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);