When We Create Blank Activity ..... What This Activity Is?: Oncreate Method in Your Main Activity Class
When We Create Blank Activity ..... What This Activity Is?: Oncreate Method in Your Main Activity Class
You are probably wondering what an Activity is in Android, and what exactly its function is. An
Activity is a screen area that holds content and user interface (UI) designs that provide a frontend (display area) for your application to interface visually with your end-users.
The main activity is defined via XML mark-up and then inflated via Java code in your application
onCreate( ) method in your Main Activity class.
NOTE:-
match_parent value tells the Relative Layout container to expand to fill the entire
display screen.
wrap content value which essentially does the exact opposite of what the
match_parent setting does. Instead of expanding the tag to fill its container,
wrap_content shrink-wraps the container.
Property android:layout_below="@+id/element1" used to set an element
just below the element1 on the layout(screen) .
---------------------
Note that: onCreateOptionsMenu(Menu menu) method just render the menu on screen but donot
respond if any menu item is selected .
2: in res/Menu/main.xml file add item like
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
By adding many item in main.xml and just overwriding onCreateOptionsMenu(Menu
menu) method is sufficient to show the manu on screen. Like in image 1.1
Image 1.1
but remeber you can see the menu but it is not going to work now.
-----------------------
For example in our image 1.1 for menu Item 'Add A New Item' we added an Activity class named
NewPlanet.java
2: Inside the NewPlanet.java class override a method named
onCreate(Bundle savedInstanceState)
3: Inside
------------------------
For exapmle:
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="@string/text_namokar_hindi" />
in above android:gravity property is used to send text at the centre horizontallyof TextView Object
but android:layout_gravity will move the entire TextView object at the centre horizontally on
screen.
------------------------
Android Toast Class (android.widget.Toast) :Android Toast objects are used to send messages onto your Activity screen that appear for a
predefined period of time sending a message to the user.
Declaring a Toast object is done most simply by using the .makeToast() method off of a
Toast object.
The method requires : the current context
the message to be Toasted
the duration in the form of a constant.