I've seen several threads related to a similar question but I haven't been able to successfully apply it to my case. Actually I'm trying to change the style of a button when it's clicked by the user using a ContextThemeWrapper. So initially the button is set to a certain style that I linked inside the XML document, and I include this code to try to make it change in appearance by using a ContextThemeWrapper and according to what was advised in the first link below. The problem (I think) is that I don't know how to link that newly created button to the physical object that I see on the screen. Any suggestion is welcome! Thanks!
public class MainActivity extends AppCompatActivity {
private Button TestButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TestButton = findViewById(R.id.button);
TestButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ContextThemeWrapper newContext = new ContextThemeWrapper(getApplicationContext(), R.style.custom);
TestButton = new TextView(newContext);
}
});
}
}
Here are the links I'm referrring to: ContexThemeWrapper to change style General question about different contexts