Introduction

The Static Text Toggle Button UI component is like a Static Text Button UI element except that after it is pressed it remains active until it is pressed again. It has four states: enabled, pressed, active, and disabled.

Creation from XML

You need to create a new com.att.widgets.lib.button.StaticTextToggleButton object and add it to your view or layout.

	<com.att.widgets.lib.button.StaticTextToggleButton  
	    android:layout_width="fill_parent" 
	    android:layout_height="wrap_content" 
	    android:text="Static Text Toggle Button"
        />

Creation from Code

package com.att.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;

import com.att.widgets.lib.button.StaticTextToggleButton;

public class StaticTextToggleButtonActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        StaticTextToggleButton toggleButtonDisabled = (StaticTextToggleButton) findViewById(R.id.toggle_disabled);
        toggleButtonDisabled.setEnabled(false);
        
        StaticTextToggleButton toggleButton = new StaticTextToggleButton(this);
        toggleButton.setText("Toggle Button added by code");
        
        ViewGroup view = (ViewGroup) findViewById(R.id.toggle_button_main);
        view.addView(toggleButton);
    }
}

Full Layout Code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10sp"
    android:id="@+id/toggle_button_main"
    >
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:text="This is a Static Text Toggle Button"
		 />
		
	<com.att.widgets.lib.button.StaticTextToggleButton  
	    android:layout_width="fill_parent" 
	    android:layout_height="wrap_content" 
	    android:text="Static Text Toggle Button"
	    android:id="@+id/toggle_enabled"
	    android:layout_marginTop="5dip"
        />
    
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:text="This is a disabled Static Text Toggle Button"
	    android:layout_marginTop="10dip"
		/>
		
	<com.att.widgets.lib.button.StaticTextToggleButton  
	    android:layout_width="fill_parent" 
	    android:layout_height="wrap_content" 
	    android:text="Disabled Static Text Toggle Button"
	    android:id="@+id/toggle_disabled"
	    android:layout_marginTop="5dip"
    />
    
   <TextView android:layout_width="fill_parent"
   		android:layout_height="wrap_content" 
		android:text="This is a Static Text Toggle Button created in code"
	    android:layout_marginTop="10dip"
		/>    
</LinearLayout>

Disabled State

To disable the text toggle button, set the enabled property to false.

        toggleButtonDisabled.setEnabled(false);