将事件传递给android中的所有相关视图

时间:2016-05-11 11:23:04

标签: java android

有没有办法一次更改多个TextView文字大小?它们可能也可能不是单ViewGroup。我希望通过创建某种类似于pub / sub但却没有想法的触发器/事件来做。任何可能性?

1 个答案:

答案 0 :(得分:0)

You could just use a class which you register the TextViews with. Then have a method which goes through all the registered TextViews and sets the font size. Somethings like:

public class TextViewTextSizer {

    private List<TextView> textViews;

    public TextViewTextSizer() {

        textViews = new ArrayList<>();
    }

    public void registerTextView(TextView textView) {

        textViews.add(textView);
    }

    public void setTextSize(float size) {

        for (TextView textView : textViews) {
            textView.setTextSize(size);
        }
    }
}