How does one go about setting styles of layouts and components from Java code? Something like the following is what I want to do:
button.setStyle(R.style.MyStyle);
How does one go about setting styles of layouts and components from Java code? Something like the following is what I want to do:
button.setStyle(R.style.MyStyle);
You can't apply style on view programmatically. Though you can do runtime inflating like below.
Create "template.xml" layout file. Which has layout of TextView with style. You can create more then one to support different style.
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Template"
style="@style/first_style" />
In activity you can inflate this layout by following code.
TextView txtView = (TextView)getLayoutInflater().inflate(R.layout.template, null);