参考所有文本视图

时间:2013-11-04 15:53:45

标签: java android xml layout textview

我正在尝试将应用中的所有文字视图的大小设置为一定的大小。

    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。

1 个答案:

答案 0 :(得分: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);
      }
  }

它不优雅,但它应该工作。检查拼写错误