I need to be able to do something like this:
if(condition){
textview.setStyle(R.styles.a1);
}else{
textview.setStyle(R.styles.a2);
}
the thing is you c开发者_C百科an't change the style at runtime, there is methods like setTextApperience and similar but not for setting the style. My question is how to set different backgrounds for the textview of some other view according to a theme, for example in themeA the color of the textview with id=tv1 is blue and for themeB the color of the textview with id=tv1 is red...
I know that this things are discussed on the forum but I couldn't find the thing I need
Edit1: I know that I can set a theme at runtime somebackground...
But my problem is how to set different backgorund for different theme for some specific element , let say element with id=textview1
you can't set the style because their is no such method was defined. but you can create the different theme in xml file and change at runtime
for e.g.
setTheme(android.R.style.Theme_Dark);
so make theme in style and used like this way
Edit:
you can set the background and textcolor like this way
if(condition){
textview.setBackground(Color.Grey);
textview.setTextColor(Color.Black);
}else{
textview.setBackground(Color.Blue);
textview.setTextColor(Color.White);
}
or check this post answer How to change a TextView's style at runtime
精彩评论