A widget is a View object that serves as an interface for interaction with the user. Android devices come fully equipped with various widgets, including buttons, check boxes, and text-entry fields, so that you can quickly build your user interface. Some widgets are more complex, such as a date picker, a clock, and zoom controls.
Widgets also provide user interface events that inform you when a user has interacted with the particular widget, such as tapping a button.
The Android documentation can get a bit sticky at times, and widgets and app widgets are regularly confused. They are two completely different topics. I am currently referring to widgets in the sense that you can find defined at http://d.android.com/reference/android/widget/package-summary.html. Please note, these are not the same as app widgets, which I will cover in Chapter 8.
For your Screen Brightness Toggle app, you need to add a single widget: the ToggleButton widget, which lets the user toggle the screen brightness of the tablet.
To add a ToggleButton to your layout, type the following code into your main.xml file, just before the </RelativeLayout> line:
<ToggleButton android:id=“@+id/toggleButton” →2 android:layout_width=“wrap_content” →3 android:layout_height=“wrap_content” →4 android:layout_centerInParent=“true” →5 android:textOn=“Dimmer On” →6 android:textOff=“Dimmer Off”/> ...