Reputation: 508
In my application I want to use theme for particular layout on button click. When user press first button theme should be black for that layout and all view within that layout should be change as per theme .
Upvotes: 3
Views: 11931
Reputation:
I hope this will help ...
I would like to tell you that you should keep all the background colors for widgets transparent first. So that you just have to change the background of your LinearLayout or RelativeLayout.
Use this ...
android:background="@android:color/transparent"
Suppose you have normal theme and a RelativeLayout (id=mainBase) a button texted "ColorChanger" (id=colBtn) as well as a textView having text "Change My Color" (id=text).
And you want to change background as well as the text color.
In your onCreate method, write this :
final RelativeLayout base = (RelativeLayout) findViewById(R.id.mainBase);
final TextView txt = (TextView) fidViewbyId(R.id.text);
colBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mainBase.setBackgroundColor(getResources().getColor(R.color.<ColorName>));
text.setTextColor(getResources().getColor(R.color.<ColorName>));
}
});
So, when you click the button, the background color of RelativeLayout and TextView text color changes and it looks like the whole theme has been changed.
Upvotes: 1