0% found this document useful (0 votes)
3 views2 pages

Android Menu App Example Code

The document contains an Android application layout defined using XML, featuring a 'Hello World!' TextView centered in a ConstraintLayout. It also includes a MainActivity class that sets up a menu with options for 'New Group', 'Setting', and 'Search', displaying a Toast message when each option is selected. The menu is defined in a separate XML file with corresponding item IDs and titles.

Uploaded by

Manisha Rathod
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Android Menu App Example Code

The document contains an Android application layout defined using XML, featuring a 'Hello World!' TextView centered in a ConstraintLayout. It also includes a MainActivity class that sets up a menu with options for 'New Group', 'Setting', and 'Search', displaying a Toast message when each option is selected. The menu is defined in a separate XML file with corresponding item IDs and titles.

Uploaded by

Manisha Rathod
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<?xml version="1.0" encoding="utf-8"?

>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>
package [Link].menu_app;

import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate([Link].menu_example,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch ([Link]())
{
case [Link].new_group:
[Link](getApplicationContext(),"item1 Selected",
Toast.LENGTH_LONG).show();
return true;
case [Link]:
[Link](getApplicationContext(),"item2 Selected",
Toast.LENGTH_LONG).show();
return true;
case [Link]:
[Link](getApplicationContext(),"item3 Selected",
Toast.LENGTH_LONG).show();
return true;
default:
return [Link](item);
}

}
}

<?xml version="1.0" encoding="utf-8"?>


<menu xmlns:android="[Link]
<item android:id="@+id/new_group"
android:title="New_Group"/>
<item android:id="@+id/setting"
android:title="Setting"/>
<item android:id="@+id/Search"
android:title="Search"/>

</menu>

You might also like