0

I've tried this solution and worked fine in XML, But how I can do the samething via code ?

enter image description here

Actually I wanna change edittext (theme: lable, text color, line color) on press of a button.

Community
  • 1
  • 1
Arsalan Mehmood
  • 1,432
  • 1
  • 15
  • 26

1 Answers1

0

In Android changing the style after creating the view is not supported. That is you can't set a style to the view dynamically. But what you can do is create that view in xml, set the style you want in the xml only and when you want to show a view, you inflate it. e.g.

    <?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="This is a template"
    style="@style/my_style" />

and now inflate tis view wherever you want to use as,

TextView myText = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);
Rohit Jagtap
  • 1,660
  • 1
  • 14
  • 12