1. Check out our app, Forums for Android! Download and leave feedback here!

change xml attribute in java code

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

  1. proskier

    proskier Active Member
    Thread Starter
    15

    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
    18

    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...