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

MenuProgram

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

MenuProgram

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
You are on page 1/ 2

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

>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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" />

</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.menu_app;

import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_example,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId())
{
case R.id.new_group:
Toast.makeText(getApplicationContext(),"item1 Selected",
Toast.LENGTH_LONG).show();
return true;
case R.id.setting:
Toast.makeText(getApplicationContext(),"item2 Selected",
Toast.LENGTH_LONG).show();
return true;
case R.id.Search:
Toast.makeText(getApplicationContext(),"item3 Selected",
Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}

}
}

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


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<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