1. Download our Official Android App: Forums for Android!

Apps change xml attribute in java code

Discussion in 'Android Development' started by proskier, Jul 16, 2010.

  1. proskier

    proskier Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    30
    Joined:
    May 12, 2010

    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
    Rank:
    None
    Points:
    18
    Posts:
    85
    Joined:
    Apr 6, 2010

    Apr 6, 2010
    85
    16
    18
    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...