0

我正在尝试将我的应用程序中所有文本视图的大小设置为特定大小。

    public void rbFontClicked(View view) {
        // Is the button now checked?
        boolean checked = ((RadioButton) view).isChecked();

        // Check which radio button was clicked
        switch(view.getId()) {
            case R.id.rbsmall:
                if (checked)
                    //eveysingletextview.setTextSize(12)
                    everysingleedittext.setTextSize(12)
                break;

            case R.id.rbmedium:
                if (checked)
                    // do nothing
                break;

            case R.id.rblarge:
                if (checked)
                    // set dimension to large font,
                break;

我将如何去引用所有的文本视图?我也需要为 Edittexts 做这件事,所以我不想单独引用每个视图,这将花费很长时间。

TIA。

4

1 回答 1

1
int size = 10;
switch(view.getId()) {
            case R.id.rbsmall:
                if (checked)
                   size = 12;
                break;  

// other case

}

  ViewGroup root = (ViewGroup) findViewById(R.id.rootLayout);
  int children = root.getChildCount();
  for (int i = 0; i < children; i++) {
      View view  = root.getChildAt(i);
      if (view instanceOf TextView) {
        TextView tmp = (TextView)view;
        view.setText(size);
      }
  }

它并不优雅,但它应该可以工作。检查错字

于 2013-11-04T16:01:45.783 回答