Ted pottel
Ted pottel

Reputation: 6983

Can I use a macro within a layout file

I have a layout file that has 16 buttons. Right now I'm changing the color, by changing all 16 buttons. There must be a better way to do this, look on google could not find anything. I figure there must be a way to do a amcro or something, so I only have to change it 1 time.

file

 <LinearLayout 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" 
android:orientation="horizontal" > 

        <Button
        android:id="@+id/butVol"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:textSize="24px"
        android:text="Volume"   
        android:textColor="#ff0000ff"
        android:layout_gravity="center" 
    />

    <Button
        android:id="@+id/butRington"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Rington"  
        android:textColor="#ff0000ff"
        android:layout_gravity="center" 
    />  


android:textColor="#ff0000ff" android:layout_marginRight="6dp" />

    <Button
        android:id="@+id/butSound2"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound2"   
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  


android:textColor="#ff0000ff" android:layout_marginRight="6dp" />

    <Button
        android:id="@+id/butSound4"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound4"   
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  

<LinearLayout 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >          
    <Button
        android:id="@+id/butSound5"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound5"   
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"
    />

    <Button
        android:id="@+id/butSound6"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound6"   
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  

  <LinearLayout 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
 android:layout_gravity="center"
android:orientation="horizontal" >          
    <Button
        android:id="@+id/butSound7"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound7"   
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"
    />

    <Button
        android:id="@+id/butSound8"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound8"   
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  


android:textColor="#ff0000ff" android:layout_marginRight="6dp" />

    <Button
        android:id="@+id/butSound10"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound10"  
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  

<LinearLayout 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
 android:layout_gravity="center"
android:orientation="horizontal" >          
    <Button
        android:id="@+id/butSound11"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound11"  
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"
    />

    <Button
        android:id="@+id/butSound12"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound12"  
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  


android:textColor="#ff0000ff" android:layout_marginRight="6dp" />

    <Button
        android:id="@+id/butSound14"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound14"  
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  


android:textColor="#ff0000ff" android:layout_marginRight="6dp" />

    <Button
        android:id="@+id/butSound16"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound16"  
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  

android:textColor="#ff0000ff" android:layout_marginRight="6dp" />

    <Button
        android:id="@+id/butSound18"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
    android:textSize="24px"
        android:text="Sound18"  
        android:textColor="#ff0000ff"
        android:layout_marginRight="6dp"    
    />  


Upvotes: 0

Views: 451

Answers (1)

minhaz
minhaz

Reputation: 4233

you are not suppose to use color code directly

android:textColor="#ff0000ff"

Replace this with android:textColor="@color/xyz"

Then define this xyz color in String.xml

Alternatively you can use theme to define style or color. then your button add the theme

android:theme="@style/xyzStyle"

Upvotes: 1

Related Questions