When click on the menu icon to open NavigationDrawer it crashes - android

When i click on the icon to open the NavigationDrawer my app suddenly crashes and i am trying to solve this about 3 days. Can anyone help me?
I am using Android Studio and this is my first app.
My problem is to open the NavigationDrawer by clicking on the icon on app bar.
Codes:
MainActivity.java
package com.example.chatapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
import de.hdodenhof.circleimageview.CircleImageView;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
Toolbar toolbar;
DrawerLayout drawerLayout;
NavigationView navigationView;
FirebaseAuth mAuth;
FirebaseUser mUser;
DatabaseReference mUserRef;
String profileImageUriV, usernameV;
CircleImageView profileImageHeader;
TextView usernameHeader;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar=findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Chat App");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu);
mAuth=FirebaseAuth.getInstance();
mUser=mAuth.getCurrentUser();
mUserRef= FirebaseDatabase.getInstance().getReference().child("Users");
drawerLayout=findViewById(R.id.drawerLayout);
navigationView=findViewById(R.id.navView);
View view=navigationView.inflateHeaderView(R.layout.drawer_header);
profileImageHeader=view.findViewById(R.id.profileImage_Header);
usernameHeader=view.findViewById(R.id.usernameHeader);
navigationView.setNavigationItemSelectedListener(this);
}
#Override
protected void onStart() {
super.onStart();
if (mUser==null)
{
SendUserToLoginActivity();
}
else{
mUserRef.child(mUser.getUid()).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists())
{
profileImageUriV=dataSnapshot.child("profileImage").getValue().toString();
usernameV=dataSnapshot.child("username").getValue().toString();
Picasso.get().load(profileImageUriV).into(profileImageHeader);
usernameHeader.setText(usernameV);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(MainActivity.this, "Sorry! Something going wrong", Toast.LENGTH_SHORT).show();
}
});
}
}
private void SendUserToLoginActivity() {
Intent intent=new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.home:
Toast.makeText(this, "Home", Toast.LENGTH_SHORT).show();
break;
case R.id.profile:
Toast.makeText(this, "Profile", Toast.LENGTH_SHORT).show();
break;
case R.id.friend:
Toast.makeText(this, "Friend", Toast.LENGTH_SHORT).show();
break;
case R.id.findFriend:
Toast.makeText(this, "Find Friend", Toast.LENGTH_SHORT).show();
break;
case R.id.chat:
Toast.makeText(this, "Chat", Toast.LENGTH_SHORT).show();
break;
case R.id.logout:
Toast.makeText(this, "Logout", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
if (item.getItemId()==android.R.id.home){
drawerLayout.openDrawer(GravityCompat.START);
return true;
}
return true;
}
}
Drawer_Menu.xml:
<group android:id="#+id/first">
<item android:id="#+id/home"
android:title="Home"
android:icon="#drawable/ic_home"/>
<item android:id="#+id/profile"
android:title="Profile "
android:icon="#drawable/ic_profile"/>
<item android:id="#+id/friend"
android:title="Friend "
android:icon="#drawable/ic_friend"/>
<item android:id="#+id/findFriend"
android:title="Find Friend "
android:icon="#drawable/ic_find_friend"/>
<item android:id="#+id/chat"
android:title="Chat "
android:icon="#drawable/ic_chat"/>
</group>
<group android:id="#+id/second">
<item android:id="#+id/logout"
android:title="Logout "
android:icon="#drawable/ic_logout"/>
</group>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/app_bar"
layout="#layout/main_appbar" />
<EditText
android:id="#+id/inputAddPost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/input_add_post_bg"
android:hint="Post something here :)"
android:paddingLeft="50dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/app_bar" />
<ImageView
android:id="#+id/addImagePost"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="#+id/inputAddPost"
app:layout_constraintStart_toStartOf="#+id/inputAddPost"
app:layout_constraintTop_toTopOf="#+id/inputAddPost"
app:srcCompat="#drawable/ic_add_post_image" />
<ImageView
android:id="#+id/send_post_imageView"
android:layout_width="53dp"
android:layout_height="48dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="#+id/inputAddPost"
app:layout_constraintEnd_toEndOf="#+id/inputAddPost"
app:layout_constraintTop_toTopOf="#+id/inputAddPost"
app:srcCompat="#drawable/send_post" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/inputAddPost"
android:background="#color/colorGray"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/drawer_menu"/>
</androidx.drawerlayout.widget.DrawerLayout>
build.gradle:
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.firebaseui:firebase-ui-database:6.2.1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'

I think You would have missed mentioning the id of the DrawerLayout in your 'activity_main.xml' through which our activity finds the Layout in the XML file
android:id="#+id/drawerLayout"
Below is the code after updating.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/app_bar"
layout="#layout/main_appbar" />
<EditText
android:id="#+id/inputAddPost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/input_add_post_bg"
android:hint="Post something here :)"
android:paddingLeft="50dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/app_bar" />
<ImageView
android:id="#+id/addImagePost"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="#+id/inputAddPost"
app:layout_constraintStart_toStartOf="#+id/inputAddPost"
app:layout_constraintTop_toTopOf="#+id/inputAddPost"
app:srcCompat="#drawable/ic_add_post_image" />
<ImageView
android:id="#+id/send_post_imageView"
android:layout_width="53dp"
android:layout_height="48dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="#+id/inputAddPost"
app:layout_constraintEnd_toEndOf="#+id/inputAddPost"
app:layout_constraintTop_toTopOf="#+id/inputAddPost"
app:srcCompat="#drawable/send_post" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/inputAddPost"
android:background="#color/colorGray"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/drawer_menu"/>
</androidx.drawerlayout.widget.DrawerLayout>

Related

why BottomSheetBehavior in androidx error The view is not a child of CoordinatorLayout?

I use androidx and material Bottom Sheet Modal persistent. but my code is error like this :
The view is not a child of CoordinatorLayout
bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="72dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_margin"
android:layout_weight="2"
android:text="Order Details"
android:textColor="#444"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:gravity="right"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="15dp"
android:text="₹435.00"></TextView>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chicken Fried Rice 1x1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Paneer Tikka 1x2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_margin"
android:text="Delivery Address"
android:textColor="#444"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Flat No 404, Skyline Apartments, Vizag - 500576" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#000"
android:foreground="?attr/selectableItemBackground"
android:text="PROCEED PAYMENT"
android:textColor="#fff" />
</LinearLayout>
activity_main.xml
<?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"
android:background="#efefef"
tools:context="com.app.MainActivity">
<include layout="#layout/content_main" />
<!-- Adding bottom sheet after main content -->
<include layout="#layout/bottom_sheet" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.app;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
#BindView(R.id.btn_bottom_sheet)
Button btnBottomSheet;
#BindView(R.id.bottom_sheet)
LinearLayout layoutBottomSheet;
BottomSheetBehavior sheetBehavior;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);
sheetBehavior = BottomSheetBehavior.from(layoutBottomSheet);
/**
* bottom sheet state change listener
* we are changing button text when sheet changed state
* */
sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
#Override
public void onStateChanged(#NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN:
break;
case BottomSheetBehavior.STATE_EXPANDED: {
btnBottomSheet.setText("Close Sheet");
}
break;
case BottomSheetBehavior.STATE_COLLAPSED: {
btnBottomSheet.setText("Expand Sheet");
}
break;
case BottomSheetBehavior.STATE_DRAGGING:
break;
case BottomSheetBehavior.STATE_SETTLING:
break;
}
}
#Override
public void onSlide(#NonNull View bottomSheet, float slideOffset) {
}
});
}
/**
* manually opening / closing bottom sheet on button click
*/
#OnClick(R.id.btn_bottom_sheet)
public void toggleBottomSheet() {
if (sheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
btnBottomSheet.setText("Close sheet");
} else {
sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
btnBottomSheet.setText("Expand sheet");
}
}
}
where I wrong, and how to solve this, I already google about this problem, but I got no clue.
error in sheetBehavior = BottomSheetBehavior.from(layoutBottomSheet);
thanks
Your parent layout is a ConstraintLayout not a CoordinatorLayout

Android Fragment to replace original contents in activity?

activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
android:id="#+id/mainLayout">
<android.support.constraint.ConstraintLayout
android:id="#+id/loginCl1"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/loginCl2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_weight="3">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="#id/loginCl1"
app:layout_constraintStart_toStartOf="#+id/loginCl1"
app:layout_constraintEnd_toEndOf="#+id/loginCl1"
app:layout_constraintBottom_toTopOf="#+id/id"
app:layout_constraintVertical_weight="4"
android:src="#drawable/logo" />
<com.fapa.brent.fapa.Common.BrentEditText
android:id="#+id/id"
android:layout_width="match_parent"
android:layout_height="0dp"
android:hint="#string/enterid"
app:layout_constraintBottom_toTopOf="#+id/pw"
app:layout_constraintEnd_toEndOf="#+id/loginCl1"
app:layout_constraintStart_toStartOf="#id/loginCl1"
app:layout_constraintTop_toBottomOf="#+id/image"
app:layout_constraintVertical_weight="1"/>
<com.fapa.brent.fapa.Common.BrentEditText
android:id="#+id/pw"
android:layout_width="match_parent"
android:layout_height="0dp"
android:hint="#string/enterpw"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="#id/loginCl1"
app:layout_constraintEnd_toEndOf="#+id/loginCl1"
app:layout_constraintStart_toStartOf="#id/loginCl1"
app:layout_constraintTop_toBottomOf="#+id/id"
app:layout_constraintVertical_weight="1"/>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/loginCl2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/loginCl1"
app:layout_constraintVertical_weight="2">
<CheckBox
android:id="#+id/saveId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/saveId"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/login"
app:layout_constraintTop_toBottomOf="#+id/saveId"
app:layout_constraintEnd_toStartOf="#id/signup"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/signup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/signup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/saveId"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="#id/login" />
<Button
android:id="#+id/findId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/findid"
app:layout_constraintEnd_toStartOf="#+id/findPw"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/login" />
<Button
android:id="#+id/findPw"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/findpw"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/findId"
app:layout_constraintTop_toBottomOf="#+id/signup" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java:
package com.fapa.brent.fapa;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.facebook.stetho.Stetho;
import com.fapa.brent.fapa.Common.BrentEditText;
import com.fapa.brent.fapa.Encryption.Sha512;
import com.fapa.brent.fapa.Form.FindIdFragment;
import com.fapa.brent.fapa.Form.FindPwFragment;
import com.fapa.brent.fapa.Form.SignUpFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* CREATED BY BRENT ON 2018-12-11
*/
public class MainActivity extends AppCompatActivity {
#BindView(R.id.id)
BrentEditText mId;
#BindView(R.id.pw)
BrentEditText mPw;
#BindView(R.id.login)
Button mBtnLogin;
#BindView(R.id.signup)
Button mBtnSignup;
#BindView(R.id.findId)
Button mBtnFindId;
#BindView(R.id.findPw)
Button mBtnFindPw;
Fragment mFragment;
#OnClick(R.id.login)
void loginValidatation() {
String id = mId.getText().toString();
String pw = Sha512.getSHA512(mPw.getText().toString());
}
#OnClick({R.id.signup, R.id.findPw, R.id.findId})
void openUpFragmentByButton(Button button){
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
switch (button.getId()){
case R.id.signup:
mFragment = new SignUpFragment();
fragmentChangeOrAdd(fragmentTransaction, mFragment);
break;
case R.id.findId:
mFragment = new FindIdFragment();
fragmentChangeOrAdd(fragmentTransaction, mFragment);
break;
case R.id.findPw:
mFragment = new FindPwFragment();
fragmentChangeOrAdd(fragmentTransaction, mFragment);
break;
default:
break;
}
}
private void fragmentChangeOrAdd(FragmentTransaction fragmentTransaction, Fragment fragment) {
if(fragmentTransaction == null) {
fragmentTransaction.add(R.id.mainLayout, fragment);
fragmentTransaction.commit();
}else {
fragmentTransaction.replace(R.id.mainLayout, fragment);
fragmentTransaction.commit();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Stetho.initializeWithDefaults(this);
}
}
Please take look at my openUpFragmentById() method. What I want to do is when I click buttons on activity_main.xml, I want to inflate one of my fragments and fill up the whole activity_main and not show the original content.
I understand that the main purpose of fragment is to divide, or split activities, but I am wondering if I can replace (or change) all original contents in activity_main.xml with the contents in one of my fragments (I know that a fragment need a viewGroup in activity_main.xml (in my case) to inflate).
Besides, if it can`t, should I have additional activities to deal with this?
If it can, please provide me useful links or advice. Thanks in advance.
I don't see your fragment xml but i face this problem and i think you must set background to your fragment xml parent layout
For example :
<LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragmentParent"
android:background="#android:color/white"
>
<!--your fragment views-->
</LinearLayout>

Clash Of Clan like NavigationView Pull Arrow

I want to create a custom view which stays visible while side drawer is closed, but by pulling that, the drawer will slide.
I had seen like this in very popular game Clash Of Clan like shown in below images:
Now I wonder if there is any way to achieve same by using DrawerLayout and NavigationView?
Finally I achieved this by adding addDrawerListener and translating the HANDLE accordingly.
Here is my ACTIVITY:
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
/**
* #author Meet Vora
*/
public class PullSliderActivity extends AppCompatActivity {
private DrawerLayout drawerLayout;
private View viewPuller;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pull_slider);
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
viewPuller = findViewById(R.id.viewPuller);
drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
viewPuller.setTranslationX(drawerView.getX() + drawerView.getWidth());
}
#Override
public void onDrawerOpened(View drawerView) {
}
#Override
public void onDrawerClosed(View drawerView) {
}
#Override
public void onDrawerStateChanged(int newState) {
}
});
}
}
Here is LAYOUT XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="#style/MyHelpActivityTheme">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#49fcea"
android:gravity="center"
android:text="This is MAIN Screen"
android:textColor="#color/black"
android:textSize="20sp"
android:textStyle="bold"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#223344"
android:gravity="center"
android:text="This is NAVIGATION View"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<TextView
android:id="#+id/viewPuller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#5f97cf"
android:clickable="false"
android:gravity="center"
android:padding="4dp"
android:text="N\n.\nV\nI\nE\nW"
android:textColor="#color/white"
android:textSize="10sp"
android:textStyle="bold"/>
</RelativeLayout>

How to properly combine NavigationView and BottomNavigationView

I need to use both elements and this is what I have at the moment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorAccent"
app:menu="#menu/menu_bottom" />
</RelativeLayout>
My problem here is that the BottomNavigationView is in front of the NavigationView, which should not be the case (I'm talking about the y-index). I also tried using a CoordinatorLayout instead, but then the BottomNavigationView is stuck at the display's top.
I would simply use DrawerLayout as the root element and inside the DrawerLayout you can put a layout for containing the main screen and a NavigationView for the menu. After you can put the BottomNavigationView into the main layout.
<android.support.v4.widget.DrawerLayout xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include layout="#layout/maincontent"/>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
maincontent.xml
<FrameLayout..>
...
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorAccent"
app:menu="#menu/menu_bottom" />
</FrameLayout>
Here this code runs perfectly for me
nav_header_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:gravity="bottom"
android:orientation="vertical"
android:background="#drawable/nav_header_background">
<LinearLayout
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="#dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/nav_header_background">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:paddingTop="#dimen/nav_header_vertical_spacing"
app:civ_border_color="#color/white"
app:civ_border_width="2dp" />
<TextView
android:id="#+id/login_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text=""
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/login_email_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#color/white" />
</LinearLayout>
</RelativeLayout>
activity_home.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout
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">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_nav_view">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="#color/colorAccentDark"
app:itemIconTint="#color/white"
app:itemTextColor="#color/white"
android:foregroundGravity="bottom"
app:menu="#menu/bottom_nav_menu" />
</RelativeLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_home"
app:menu="#menu/activity_home_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
Now the most important the Java file
HomeActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.blogspot.atifsoftwares.animatoolib.Animatoo;
import com.bumptech.glide.Glide;
import com.facebook.AccessToken;
import com.facebook.login.LoginManager;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.annotation.NonNull;
import androidx.core.view.GravityCompat;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import de.hdodenhof.circleimageview.CircleImageView;
public class HomeActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, GoogleApiClient.OnConnectionFailedListener {
private FirebaseAuth mAuth;
GoogleApiClient mGoogleApiClient;
GoogleSignInOptions gso;
FirebaseUser user;
TextView name3;
TextView emailid;
CircleImageView circleImageView;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
BottomNavigationView navView = findViewById(R.id.bottom_nav_view);
navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
View header=navigationView.getHeaderView(0);
mAuth = FirebaseAuth.getInstance();
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
user = mAuth.getCurrentUser();
name3=(TextView)header.findViewById(R.id.login_name);
emailid=(TextView)header.findViewById(R.id.login_email_id);
circleImageView=(CircleImageView) header.findViewById(R.id.imageView);
sharedPreferences=getApplicationContext().getSharedPreferences("owl_pref",MODE_PRIVATE);
editor=sharedPreferences.edit();
editor.apply();
if(sharedPreferences.getString("method","").equals("facebook")){
emailid.setText(sharedPreferences.getString("login_mail",""));
name3.setText(sharedPreferences.getString("login_name",""));
String url=sharedPreferences.getString("login_profile_image","");
Glide.with(this).load(url).placeholder(R.drawable.logo).override(124,124).into(circleImageView);
}
if(sharedPreferences.getString("method","").equals("google")){
emailid.setText(sharedPreferences.getString("login_mail",""));
name3.setText(sharedPreferences.getString("login_name",""));
String url=sharedPreferences.getString("login_profile_image","");
Glide.with(this).load(url).placeholder(R.drawable.logo).override(124,124).into(circleImageView);
}
if(sharedPreferences.getString("method","").equals("email")){
emailid.setText(sharedPreferences.getString("login_mail",""));
name3.setText(sharedPreferences.getString("login_name",""));
//String url=sharedPreferences.getString("login_profile_image","");
Glide.with(this).load(R.drawable.logo).override(124,124).into(circleImageView);
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new FragmentHomeActivity()).commit();
}
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
Fragment fragment = null;
switch (item.getItemId()) {
case R.id.navigation_home:
fragment = new FragmentHomeActivity();
break;
case R.id.navigation_dashboard:
fragment = new FragmentDashboardActivity();
break;
case R.id.navigation_star:
fragment = new FragmentRewardActivity();
break;
case R.id.navigation_discuss:
fragment = new FragmentDiscussActivity();
break;
case R.id.navigation_profile:
fragment = new FragmentProfileActivity();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit();
return true;
}
};
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the FragmentHomeActivity/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_search) {
return true;
}
return super.onOptionsItemSelected(item);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
Intent intent=new Intent(HomeActivity.this,HomeActivity.class);
startActivity(intent);
showToast("Already in Home Section");
} else if (id == R.id.nav_question_answer) {
Intent intent=new Intent(HomeActivity.this,QuestionActivity.class);
startActivity(intent);
} else if (id == R.id.nav_upload) {
Intent intent=new Intent(HomeActivity.this,UploadActivity.class);
startActivity(intent);
//Animatoo.animateFade(this);
} else if (id == R.id.nav_logout) {
signOut();
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
public void openDrawer() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.openDrawer(GravityCompat.START);
}
private void showToast(String message) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
}
private void signOut() {
user = mAuth.getCurrentUser();
editor.clear().commit();
if (user != null) {
mAuth.signOut();
Log.d("owl","enter");
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new ResultCallback<Status>() {
#Override
public void onResult(#NonNull Status status) {
Toast.makeText(HomeActivity.this, "Signed Out", Toast.LENGTH_LONG).show();
Intent intent = new Intent(HomeActivity.this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
if (AccessToken.getCurrentAccessToken() != null && com.facebook.Profile.getCurrentProfile() != null) {
LoginManager.getInstance().logOut();
Intent intent = new Intent(HomeActivity.this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
Now
activity_home_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_home_black_24dp"
android:title="#string/menu_home" />
<item
android:id="#+id/nav_question_answer"
android:icon="#drawable/ic_question_answer_black_24dp"
android:title="#string/menu_question_answer" />
<item
android:id="#+id/nav_upload"
android:icon="#drawable/ic_cloud_upload_black_24dp"
android:title="#string/menu_upload" />
<item
android:id="#+id/nav_logout"
android:icon="#drawable/ic_exit_to_app_black_24dp"
android:title="#string/menu_logout" />
</group>
<!--<item android:title="Extras">
<menu>
<item
android:id="#+id/nav_pricing"
android:icon="#drawable/ic_attach_money_black_24dp"
android:title="#string/menu_pricing" />
</menu>
</item>-->
</menu>
bottom_nav_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_home"
android:icon="#drawable/ic_home_black_24dp"
android:title="#string/title_home">
</item>
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/ic_dashboard_black_24dp"
android:title="#string/title_dashboard">
</item>
<item
android:id="#+id/navigation_star"
android:icon="#drawable/ic_star_black_24dp"
android:title="#string/title_star">
</item>
<item
android:id="#+id/navigation_discuss"
android:icon="#drawable/ic_chat_black_24dp"
android:title="#string/title_discuss">
</item>
<item
android:id="#+id/navigation_profile"
android:icon="#drawable/ic_perm_identity_black_24dp"
android:title="#string/title_profile">
</item>
</menu>
The main thing is in the drawer layout the bottom navigation view is inserted
THE BOTTOM NAVIGATION VIEW IS WORKING WITH THE FRAME LAYOUT IN THE activity_home.xml one activity is holding the Bottom Navigation View

Make Drawer Navigation Menu Item Open new activity when clicked

I'm new to android app development and am trying to build an app. I have successfully built my navigation drawer but I want the menu items to open another activity when clicked. I have tried various answers on SO but my app seems to crash each time i run my app after applying any of the answers. Please what could be the cause of this.
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/my_account"
android:title="My Account"
android:icon="#mipmap/ic_person_white_24dp"
android:onClick="settings"></item>
<item
android:id="#+id/my_settings"
android:title="Settings"></item>
<item
android:id="#+id/Logout"
android:title="Log Out"
android:icon="#mipmap/ic_exit_to_app_white_24dp"></item>
</menu>
activity.java
package com.example.orume.export;
import android.content.Intent;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class WorkActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
private Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work);
mToolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawerLayout);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.string.open,
R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final Button bExplore = (Button) findViewById(R.id.bExplore);
bExplore.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent exploreIntent = new Intent(WorkActivity.this,
RegisterActivity.class);
WorkActivity.this.startActivity(exploreIntent);
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mToggle.onOptionsItemSelected(item)){
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_search, menu);
return true;
}
}
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/drawerLayout"
android:background="#d8dadc">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#menu/navigation_menu"
android:layout_gravity="start"
android:background="#color/colorPrimary"
app:headerLayout="#layout/navigation_header">
</android.support.design.widget.NavigationView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#d8dadc">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="false"
android:padding="10dp">
<Button
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="0.5"
android:background="#mipmap/bg_tool"
android:id="#+id/bExplore"
android:layout_marginRight="5dp"/>
<Button
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="0.5"
android:background="#mipmap/bg_tool_2"
android:id="#+id/bPrice"
android:layout_marginLeft="5dp"
android:text="Explore"
android:textAllCaps="false"
android:textColor="#191919"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="false"
android:padding="10dp"
android:layout_marginTop="75dp">
<Button
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="0.5"
android:background="#mipmap/bg_tool"
android:id="#+id/bS"
android:layout_marginRight="5dp"/>
<Button
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="0.5"
android:background="#mipmap/bg_tool_2"
android:id="#+id/bA"
android:layout_marginLeft="5dp"
android:text="Explore"
android:textAllCaps="false"
android:textColor="#191919"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
In your menu.xml you have added this line android:onClick="settings". remove that line or add the following code to your MainActivity.java
public boolean settings(MenuItem item) {
// actions
return true;
}

Categories

Resources