change xml attribute in java code


Last Updated:

  1. proskier

    proskier Active Member This Topic's Starter

    Joined:
    May 12, 2010
    Messages:
    30
    Likes Received:
    0
    is there anyway to do something like this:

    Code (Text):
    1. R.layout.main(@+id/peanuts(android:background))  = "#E1F1CD";
    so from your code you could change attributes???
     

    Advertisement
  2. Boogs

    Boogs Well-Known Member

    Joined:
    Apr 6, 2010
    Messages:
    85
    Likes Received:
    16
    Yes, effectively there is. However, not quite in the way you're thinking. You need to get a reference to your widget, and then call one of its internal methods that related to the Xml attributes. For example:
    Code (Text):
    1.  
    2. Button  button = (Button)findViewById(R.id.button);
    3. button.setText("Press Me");
    4.  
    That code takes the place of one of the Xml attributes related to the text. They have more functions which are related to their background colors, etc. You just need to check the class's page on the android developer site, and it will tell you all the functions.
     

Share This Page

Loading...