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

Mainactivity Java

This document defines a Java class called MainActivity that extends AppCompatActivity. It sets up a navigation drawer for an Android app with a toolbar and navigation menu. When a menu item is selected, different intents are started like viewing the app's privacy policy or sharing the app. The toolbar and navigation drawer toggle are also configured to open and close the drawer layout.

Uploaded by

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

Mainactivity Java

This document defines a Java class called MainActivity that extends AppCompatActivity. It sets up a navigation drawer for an Android app with a toolbar and navigation menu. When a menu item is selected, different intents are started like viewing the app's privacy policy or sharing the app. The toolbar and navigation drawer toggle are also configured to open and close the drawer layout.

Uploaded by

abijar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.jarves.

navigationdrawer;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.navigation.NavigationView;

public class MainActivity extends AppCompatActivity {

DrawerLayout drawerLayout;
ActionBarDrawerToggle actionBarDrawerToggle;
NavigationView navigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpToolbar();
navigationView = (NavigationView) findViewById(R.id.navigation_menu);
navigationView.setNavigationItemSelectedListener(new
NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId())
{
case R.id.nav_home:

Intent intent = new Intent(MainActivity.this,


MainActivity.class);
startActivity(intent);
break;

//Paste your privacy policy link

// case R.id.nav_Policy:{
//
// Intent browserIntent = new Intent(Intent.ACTION_VIEW ,
Uri.parse(""));
// startActivity(browserIntent);
//
// }
// break;
case R.id.nav_share:{

Intent sharingIntent = new


Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody =
"http://play.google.com/store/apps/detail?id=" + getPackageName();
String shareSub = "Try now";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSub);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share
using"));

}
break;
}
return false;
}
});
}
public void setUpToolbar() {
drawerLayout = findViewById(R.id.drawerLayout);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
toolbar, R.string.app_name, R.string.app_name);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();

}
}

You might also like