Google added the action bar after the Android4.0. But sometimes the title bar takes up quite a lot of screen space, making the content area smaller, showing how to hide the title bar.
The way to hide the title bar is simple, open the firstactivity of the previous section, and add the following code to the OnCreate () method:
protected void onCreate (Bundle savedinstancestate) { super. OnCreate (savedinstancestate); // Hide title bar requestwindowfeature (window.feature_no_title); // load the layout in the activity, using the Setcontentview () method Setcontentview (r.layout.first_layout);
}
where Requestwindowfeature (window.feature_no_title) is not displaying the title bar in the activity (note: This code must be executed before Setcontentview ().)
After running the code, the effect looks like this:
A toast is a reminder that is provided by the Android system, which can be used in a program to notify users of short messages, but this information disappears automatically after a period of time and does not occupy any screen space.
You need to define a trigger point when using a toast, as shown in the Buttons 1 button on the above section as the trigger point. A toast will pop up when the user Taps button 1 o'clock. Then add the following in the OnCreate () method
Code:
1 protected voidonCreate (Bundle savedinstancestate) {2 Super. OnCreate (savedinstancestate);3 //Hide title bar4 requestwindowfeature (window.feature_no_title);5 //load the layout in the activity, using the Setcontentview () method6 Setcontentview (r.layout.first_layout);7 8 Button button1 = (Button) Findviewbyid (r.id.button_1); 9 Button1.setonclicklistener (new Onclicklistener () { Ten Public void OnClick (View v) { One Toast.maketext (firstactivity. this, "You clicked Button 1", A toast.length_short). Show (); - } - }); the}
In the code:
The Findviewbyid () method gets to the element defined in the layout file (which is passed in r.id.button_1 to get the instance of the button), and the Findviewbyid () method returns a View object that needs to be forced to
The button object. After you get an instance of the button, register a listener for the button by calling the Setonclicklistenter () method, and then click the button to execute the onclick () method in the listener.
The use of toast is to create a Toast object from a static method Maketext () and then call Show () to display the toast.
The Maketext () method requires the passing of three parameters,
(1) The first parameter is the context, is a toast requirement, and the activity is a contextual object, the above code is directly passed into the firstactivity.this.
(2) The second parameter is the text content of the toast display.
(3) The third parameter is the length of the toast display, and the API provides the Toast.length_short and Toast.length_long two built-in constants.
Re-run the program, click the button, will get the effect:
Android Learning notes (ii)