【问题标题】:Change Text Size of all RecyclerView with one SeekBar - Android Studio使用一个 SeekBar 更改所有 RecyclerView 的文本大小 - Android Studio
【发布时间】:2021-04-20 13:40:28
【问题描述】:

我有一个回收器视图和一个带有自定义适配器的 ArrayList。我想设置一个 SeekBar 来同时更改数组中所有值的文本大小,这可能吗? 当我在活动中使用 SeekBar 时,它只会更改第一行的文本大小,仅此而已。提前致谢。

编辑: 我的主要活动中的代码:

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) {

            }
        });

【问题讨论】:

    标签: android android-studio android-seekbar


    【解决方案1】:

    是的,您可以在适配器中创建一个 setTextSizes 方法,并通过基于 seekbar 值的动态搜索从活动中调用此方法。

    适配器中的方法

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

    在onBindViewHolder中添加这段代码 holder.textview.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-20
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      • 2015-02-01
      • 1970-01-01
      • 2015-05-20
      相关资源
      最近更新 更多