I am creating several textviews that all use the same style. I am attempting to use a SeekBar to update the textsize within the Style so it applies to all textviews with a minimal amount of code. I know I can use a SeekBar to set the textsize of the textviews individually but that seems like a lot of work. The problem is that everywhere I look all I find is that you cannot change the style. Is there any other work around besides doing code like below:
Define my textviews
TextView tv1 = (TextView)findViewById(R.id.tv1); TextView tv2 = (TextView)findViewById(R.id.tv2); TextView tv3 = (TextView)findViewById(R.id.tv3); Inside my SeekBar
progress = seekBarProgress; if(progress == 0) { tv1.setTextSize(12); tv2.setTextSize(12); tv3.setTextSize(12); } if(progress == 1) { tv1.setTextSize(14); tv2.setTextSize(14); tv3.setTextSize(14); } Etc etc..
I would like to be able to change one attribute of a custom style. I cannot change it all together to a different custom style because I am going to do SeekBars for Text size, text color, background color, etc. If I did custom styles for each one there would be TONS.
Since I will have a lot of textviews doing this method seems illogical. Is there a better way? Thanks.
GOT THE ANSWER!
Instead of changing the style I retrieve the child and then the child of that child and change it accordingly like below.
LinearLayout masterLayout = (LinearLayout)findViewById(R.id.masterLayout); int childCount = masterLayout.getChildCount(); for(int i = 0; i < childCount; i++) { LinearLayout innerChild = ((LinearLayout)masterLayout.getChildAt(i)); int childOfChildCount = innerChild.getChildCount(); for(int x = 0; x < childOfChildCount; x++) { ((TextView)innerChild.getChildAt(x)).setTextSize(30); } }