Я сталкиваюсь с такой проблемой. Я должен установить переключатель ящика в моем приложении, но когда я его запускаю, он не отображает ящик. У кого-нибудь есть идеи по поводу вида ошибки. Потому что, когда я проверяю свой код, в нем нет ошибок. Кстати, я не знаю, где в моем коде нужно что-то делать с этим.
package com.core.core_techapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.navigation.NavigationView;
public class Nav extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
private DrawerLayout drawer;
TextView navName, navEmail;
ImageView navImage;
GoogleSignInClient mGoogleSignInClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navtech);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().replace(R.id.drawer_layout,
new HomeFragment()).commit();
navigationView.setCheckedItem(R.id.nav_home);
}
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
navName = (TextView) navigationView.getHeaderView(0).findViewById(R.id.customerName);
navEmail = (TextView) navigationView.getHeaderView(0).findViewById(R.id.customerEmail);
navImage = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.imageView);
//GET NAME AND EMAIL
GoogleSignInAccount acct;
acct = GoogleSignIn.getLastSignedInAccount(this);
if (acct != null) {
//This process is to fetch data from Gmail accounts that are signed in with the device.
String personName = acct.getDisplayName();
//String personGivenName = acct.getGivenName();
//String personFamilyName = acct.getFamilyName();
String personEmail = acct.getEmail();
Uri personPhoto = acct.getPhotoUrl();
navName.setText(personName);
navEmail.setText(personEmail);
Glide.with(this).load(String.valueOf(personPhoto)).into(navImage);
}
}
private void signOut() {
mGoogleSignInClient.signOut()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(Nav.this, "Signed out successfully!", Toast.LENGTH_LONG).show();
finish();
}
});
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.nav_home:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new HomeFragment()).commit();
break;
case R.id.nav_complaint:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new ComplaintFragment()).commit();
break;
case R.id.nav_about:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new AboutFragment()).commit();
break;
case R.id.nav_map:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new MapFragment()).commit();
break;
case R.id.nav_logout:
signOut();
break;
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
}