使用不同的ID为多个textview设置textsize

时间:2016-08-29 00:13:26

标签: android menu textview

我正在尝试使用不同的ID为多个textview设置文本大小。此外,每个文本视图都在其自己的片段中查看和滑动视图寻呼机。

但问题是这个代码只适用于第一个和第二个ID,其余的没有改变。另外,如果我删除if(sT!= null)我得到零点错误。

CsgoRr.getModel()

1 个答案:

答案 0 :(得分:0)

我认为此代码段没有任何问题

int[] ids = {R.id.text_view_thread0, R.id.text_view_thread1, R.id.text_view_thread2, R.id.text_view_thread3,
                R.id.text_view_thread4, R.id.text_view_thread5, R.id.text_view_thread6, R.id.text_view_thread7,
                R.id.text_view_thread8, R.id.text_view_thread9, R.id.text_view_thread10, R.id.text_view_thread11,
                R.id.text_view_thread12, R.id.text_view_thread13, R.id.text_view_thread14, R.id.text_view_thread15,
                R.id.text_view_thread16, R.id.text_view_thread17, R.id.text_view_thread18};
        for (int id : ids){
            TextView sT = (TextView) findViewById(id);
            if (sT != null)
            sT.setTextSize(9);

我试过这个,它设置增量字体大小如下:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    int[] ids = {R.id.t1, R.id.t2,  R.id.t3,  R.id.t4,  R.id.t5,  R.id.t6,  R.id.t7,  R.id.t8};
    for (int i = 0; i < ids.length; i++) {
        TextView sT = (TextView) findViewById(ids[i]);
        if (sT != null)
            sT.setTextSize(9 + i);
    }
}

这很好用。因为我无权在下面的问题发表评论,所以我不得不写下答案。请提供更多有关您问题的提示。

Github参考:https://github.com/kuldeepiitg/FontSize

相关问题