Open Navigation Drawer with layout on click event - java

I have two navigation drawer, one with a ListView and the second with a Layout. The first Navigationdrawer works fine, but the second can't open it on a button click.
Here is the MainActivity xml code:
<LinearLayout
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:fitsSystemWindows="true"
android:layout_gravity="right"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/orange"
android:id="#+id/toolbar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:navigationIcon="#drawable/arrow"
app:title="MyGames"
>
<Button
android:id="#+id/rigthMenu"
android:background="#drawable/compose"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginRight="5dp"
android:layout_gravity="right" />
</android.support.v7.widget.Toolbar>
</RelativeLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollIndicators="bottom">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="2dp"
android:background="#ffffff"
android:scrollbars="vertical"/>
<include
android:id="#+id/layRigth"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
layout="#layout/rigth_menu" />
</android.support.v4.widget.DrawerLayout>
Here is the rigthMenu layout xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="left">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="#+id/checkBox2"
android:layout_gravity="center_horizontal" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="#+id/checkBox"
android:layout_gravity="center_horizontal" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="#+id/checkBox4"
android:layout_gravity="center" />
and here is the MainActivity OnCreate code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// mDrawerLayout2 = (DrawerLayout)findViewById(R.id.layRigth);
android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onIcon = !onIcon;
if (onIcon == true) {
mDrawerLayout.openDrawer(mDrawerList);
} else {
mDrawerLayout.closeDrawer(mDrawerList);
}
}
});
Button rigthMenu = (Button)findViewById(R.id.rigthMenu);
rigthMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final LayoutInflater factory = getLayoutInflater();
final View text = factory.inflate(R.layout.rigth_menu, null);
mDrawerLayout2 = (DrawerLayout)text.findViewById(R.id.layRigth);
mDrawerLayout2.openDrawer(mDrawerLayout2);
}
});
Drawable x = toolbar.getNavigationIcon();
getDefaultSettings("Image", this);
// mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.content_frame,new TabFragment()).commit();
// Initializing
dataList = new ArrayList<DrawerItem>();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// Add Drawer Item to dataList
dataList.add(new DrawerItem(R.mipmap.ps4miniatura, GREEN, 1));
dataList.add(new DrawerItem(R.mipmap.ps4miniatura, "PC", 0));
dataList.add(new DrawerItem(0, " ", 2));
adapter = new CustomDrawerAdapter(this, R.layout.custom_drawer_item, adapter,
dataList);
// addItem.giveAdapter(adapter);
mDrawerList.setAdapter(adapter);
mDrawerList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
if (savedInstanceState == null) {
SelectItem(1);
}
}
Logcat error:
12-08 08:40:52.936 15587-15587/com.tutecentral.navigationdrawer E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tutecentral.navigationdrawer, PID: 15587
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.widget.DrawerLayout.openDrawer(android.view.View)' on a null object reference
at com.tutecentral.navigationdrawer.MainActivity$2.onClick(MainActivity.java:75)
at android.view.View.performClick(View.java:4820)
at android.view.View$PerformClick.run(View.java:20157)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5578)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
I have a nullPointException. How can I get the view of the layout rigthMenu?

There are a few errors in the rigthMenu's OnClickListener. Firstly, there's no need to inflate the rigth_menu layout there. You've included it in the main layout, so it will already be inflated. Also, rigth_menu does not contain any View with ID layRigth, so text.findViewById(R.id.layRigth) is returning null, and causing the NullPointerException. And, you've already got a reference to the DrawerLayout - mDrawerLayout - so you don't need to find it again.
rigthMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(mDrawerLayout.isDrawerOpen(GravityCompat.END)) {
mDrawerLayout.closeDrawer(GravityCompat.END);
}
else {
mDrawerLayout.openDrawer(GravityCompat.END);
}
}
});

Please use below code to open and close the drawer
public void toggleDrawer() {
if (mDrawerLayout.isDrawerOpen(GravityCompat.START))
mDrawerLayout.closeDrawer(GravityCompat.START);
else
mDrawerLayout.openDrawer(GravityCompat.START);
}

Related

Why My hamburger icon in android app is not working it is not opening the navigation menu?

I am working on an app but there is a problem with hamburger icon as it is not working. It is not opening the navigation menu when i am clicking on it. what is the problem please tell me? I am trying to solve it but dont know what is the problem with it. I am new to code please help me.
Here is my fragment code
public class HomeFragment extends Fragment{
NavigationView navigationView;
ActionBarDrawerToggle toggle;
DrawerLayout drawerLayout;
Toolbar toolbar;
private int[] images;
private SliderAdapter sliderAdapter;
public HomeFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
navigationView = view.findViewById(R.id.navmenu);
drawerLayout = view.findViewById(R.id.drawerlayout);
toolbar = view.findViewById(R.id.toolbar);
ActionBar mActionBar;
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
Objects.requireNonNull(((AppCompatActivity) getActivity()).getSupportActionBar()).setTitle("");
toggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, R.string.open, R.string.close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((AppCompatActivity) getActivity()).getSupportActionBar().setHomeAsUpIndicator(R.drawable.menu3);
return view;
}
}
Here is my XML file
<?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"
android:id="#+id/drawerlayout"
tools:openDrawer="start"
android:background="#color/white"
tools:context=".HomeFragment">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/reddark"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/Theme.AppCompat.Light">
<ImageView
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/backsssososos" />
</androidx.appcompat.widget.Toolbar>
<RelativeLayout
android:id="#+id/search_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="#color/reddark"
android:padding="10dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<EditText
android:id="#+id/searchbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/searchbardesign"
android:backgroundTint="#F8F8F8"
android:drawableLeft="#android:drawable/ic_menu_camera"
android:drawableRight="#android:drawable/ic_menu_search"
android:drawablePadding="22dp"
android:gravity="left|center"
android:hint="Enter City,Colony name..."
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1"
android:padding="10dp"
android:textColor="#color/black"
android:textColorHint="#android:color/darker_gray"
android:textSize="16dp" />
</RelativeLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<com.smarteist.autoimageslider.SliderView
android:id="#+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:sliderAnimationDuration="600"
app:sliderAutoCycleDirection="back_and_forth"
app:sliderAutoCycleEnabled="true"
app:sliderIndicatorAnimationDuration="600"
app:sliderIndicatorGravity="center_horizontal|bottom"
app:sliderIndicatorMargin="15dp"
app:sliderIndicatorOrientation="horizontal"
app:sliderIndicatorPadding="3dp"
app:sliderIndicatorRadius="2dp"
app:sliderIndicatorSelectedColor="#5A5A5A"
app:sliderIndicatorUnselectedColor="#FFF"
app:sliderScrollTimeInSec="1"
app:sliderStartAutoCycle="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_file_2"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_file_2">
</TextView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navmenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemIconTint="#color/black"
android:theme="#style/NavigationDrawerStyle"
app:headerLayout="#layout/navheader"
app:itemTextColor="#151515"
app:menu="#menu/navigationmenu">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
you must attach toolbar in ActionBarDrawerToggle
mDrawerToogle = new ActionBarDrawerToggle(this, drawer,toolbar,R.string.navigation_drawer_open, R.string.navigation_drawer_close);
bar.setHomeButtonEnabled(true);
bar.setDisplayHomeAsUpEnabled(true);
mDrawerToogle.syncState();
drawer.setDrawerListener(mDrawerToogle);
you have to handle this action by yourself
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
drawerLayout.openDrawer(Gravity.LEFT);
return true;
}
return super.onOptionsItemSelected(item);
}
also syncState() call should be placed in onPostCreate or even in onResume
btw. your empty constructor should at least call super();

Make the layout below button

In one of my fragment class, it has two buttons (A and B) on top, used to switch to another fragment when clicked using viewPager.
When buttonA is clicked, it should switch to page A and so on.
When I click button A, how can I make the text in A show below the two buttons?
fragment_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:padding="15dp"
android:text="ButtonA"
android:textSize="12sp" />
<Button
android:id="#+id/buttonB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp"
android:layout_toRightOf="#+id/buttonB"
android:backgroundTint="#color/materialGrey600"
android:padding="15dp"
android:text="ButtonB"
android:textSize="12sp" />
<androidx.viewpager.widget.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
MenuFragment
public class MenuFragment extends BaseFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_menu, container, false);
final ViewPager viewPager = (ViewPager) v.findViewById(R.id.pager);
viewPager.setAdapter(new ViewPagerAdapter(getActivity().getFragmentManager()));
Button btnA = (Button) v.findViewById(R.id.buttonA);
Button btnB = (Button) v.findViewById(R.id.buttonB);
btnA.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
viewPager.setCurrentItem(0, true);
}
});
btnB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
viewPager.setCurrentItem(1, true);
}
});
return v;
}
}
ViewPagerAdapter
public class ViewPagerAdapter extends FragmentPagerAdapter {
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position)
{
case 0:
return new A()
case 1:
return new B()
}
return null;
}
#Override
public int getCount() {
return 2;
}
}
Output
try with below code.hope it is helpful for you ;)
P.S. You just need to set button style as you want :)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager.widget.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_above="#id/llButton"
android:layout_height="match_parent" />
<LinearLayout
android:id="#+id/llButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp">
<Button
android:id="#+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="15dp"
android:text="ButtonA"
android:textSize="12sp" />
<Button
android:id="#+id/buttonB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp"
android:backgroundTint="#color/colorAccent"
android:padding="15dp"
android:text="ButtonB"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
Since you are using Relative Layout you can add layout_below
<androidx.viewpager.widget.ViewPager
android:layout_below="#id/buttonB"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
you are doing it wrong, You cannot align a button to itself. That's why your buttons are not working properly. In your button B do this:
android:layout_toRightOf="#+id/buttonA"
instead of this:
android:layout_toRightOf="#+id/buttonB"
And to your viewPager add "android:layout_below:"
<androidx.viewpager.widget.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/buttonA" />
You have to set your layout like this....
[I think you want something like this 2 button fisrt and then viewpager for change the content ][1]
[1]: https://i.stack.imgur.com/dluXA.png
**Code for main Page **
<?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:layout_width="match_parent"
android:orientation="vertical"
android:padding="5dp"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:padding="10dp"
android:layout_marginTop="10dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<Button
android:id="#+id/btn_donner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#drawable/rect_outline"
android:text="Donor's"
android:textAlignment="center"
android:textColor="#color/white" />
<Button
android:id="#+id/btn_blood_bank"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Blood Bank"
android:background="#drawable/rect_outline"
android:layout_weight="2"
android:textAlignment="gravity"
android:textColor="#color/white" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
Code For Java File of two Buttons And ViewPager
//Click Event for donor's and blood bank .....
View.OnClickListener listener = new View.OnClickListener() {
#Override
public void onClick(View view) {
Fragment fragment = null;
if (view == view.findViewById(R.id.btn_donner))
{
fragment = new TabDonnerFragment();
}
else
{
fragment = new TabBloodBankFragment();
}
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.frame_content, fragment);
transaction.commit();
}
};
btn_donner.setOnClickListener(listener);
btn_blood_bank.setOnClickListener(listener);
return root;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fragment fragment = null;
fragment = new TabDonnerFragment();
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.frame_content, fragment);
transaction.commit();
}
}

Error FrameLayout in android 6 But not library [duplicate]

This question already has answers here:
java.lang.IllegalStateException: Underflow in restore - more restores than saves
(4 answers)
Closed 5 years ago.
Image for Example
ChildFragment Exmple
OneFragment.java
public class OneFragment extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("Fragment Demo", "Fragment_One onCreate()");
}
public OneFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_one, container, false);
return rootView;
}
#Override
public void onAttach(Context newBase) {
super.onAttach(CalligraphyContextWrapper.wrap(newBase));
}
}
fragment_one.xml
<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"
tools:context=".fragment.OneFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#color/grey_blue_100"
android:src="#android:drawable/ic_dialog_alert"/>
<TextView
android:gravity="center"
android:textSize="16sp"
android:textColor="#color/grey_blue_100"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="نقشه گوگل در حال حاضر در دسترس نمی باشد"/>
</LinearLayout>
</RelativeLayout>
MainFragment.java
public class RegisterFragment extends Fragment implements View.OnClickListener {
private FragmentActivity myContext;
private Fragment fragment;
private View rootView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("Fragment Demo", "Fragment_One onCreate()");
}
public RegisterFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_register_6, container, false);
Button btnOne = (Button) rootView.findViewById(R.id.btn_one);
btnOne.setOnClickListener(this);
Button btnTwo = (Button) rootView.findViewById(R.id.btn_two);
btnTwo.setOnClickListener(this);
Button btnFinal = (Button) rootView.findViewById(R.id.btn_three);
btnFinal.setOnClickListener(this);
// This is default Fragment for RegisterFragment
setFragmentUp(new OneFragment());
return rootView;
}
#Override
public void onClick(View v) {
fragment = null;
switch (v.getId()) {
case R.id.btn_one:
fragment = new OneFragment();
break;
case R.id.btn_two:
fragment = new TwoFragment();
break;
case R.id.btn_three:
fragment = new FinalFragment();
break;
default:
break;
}
if (fragment != null) {
setFragmentUp(fragment);
}
}
#Override
public void onAttach(Activity activity) {
myContext = (FragmentActivity) activity;
super.onAttach(activity);
}
protected void setFragmentUp(Fragment fragment) {
myContext.getSupportFragmentManager().beginTransaction()
.replace(R.id.fragRegisterUp, fragment, fragment.getClass().getSimpleName()).addToBackStack(null).commit();
}
#Override
public void onAttach(Context newBase) {
super.onAttach(CalligraphyContextWrapper.wrap(newBase));
}
}
fragment_main.xml
<LinearLayout
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="#color/colorAccent"
android:orientation="vertical"
tools:context="com.fanavartech.android.ham_bar_v002.fragment.RegisterFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:background="#android:color/white"
android:orientation="horizontal">
<com.andexert.library.RippleView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:rv_rippleDuration="114"
app:rv_color="#color/colorPrimaryDark"
rv_centered="true">
<Button
android:id="#+id/btn_one"
android:layout_width="match_parent"
android:text="اطلاعات بار"
android:textSize="16sp"
android:textStyle="bold"
android:background="#null"
android:layout_height="match_parent"/>
</com.andexert.library.RippleView>
<com.andexert.library.RippleView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:rv_rippleDuration="114"
app:rv_color="#color/colorPrimaryDark"
rv_centered="true">
<Button
android:id="#+id/btn_two"
android:text="اطلاعات مسیر"
android:textSize="16sp"
android:textStyle="bold"
android:background="#null"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.andexert.library.RippleView>
<com.andexert.library.RippleView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:rv_rippleDuration="114"
app:rv_color="#color/colorPrimaryDark"
rv_centered="true">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/btn_three"
android:text="پرداخت"
android:textSize="16sp"
android:textStyle="bold"
android:background="#null"/>
</com.andexert.library.RippleView>
</LinearLayout>
<FrameLayout
android:id="#+id/fragRegister"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="16dp"/>
</LinearLayout>
MainActivity.java
public class FirstActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.drawer_open , R.string.drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
Toast.makeText(FirstActivity.this, "ثبت بار", Toast.LENGTH_SHORT).show();
toolbar.setTitle(R.string.nav_register);
Fragment fragment = new RegisterFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.container_body, fragment, fragment.getClass().getSimpleName()).addToBackStack(null).commit();
}
activity_main.xml
<android.support.v4.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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"/>
</LinearLayout>
<android.support.percent.PercentFrameLayout
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<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/header"
app:menu="#menu/activity_main_drawer"/>
</android.support.v4.widget.DrawerLayout>
Error Massage
06-05 13:16:55.049 4867-4867/com.fanavartech.android.ham_bar__v002 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.ham_v002, PID: 4867
java.lang.IllegalStateException: Underflow in restore - more restores than saves
at android.graphics.Canvas.native_restore(Native Method)
at android.graphics.Canvas.restore(Canvas.java:540)
at com.andexert.library.RippleView.draw(RippleView.java:166)
at android.view.View.updateDisplayListIfDirty(View.java:15174)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
at android.view.View.updateDisplayListIfDirty(View.java:15134)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2615)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
for Android version 6 error, but at lower Android working properly.
Where is the problem?
You can try two approaches:
"Just downgrade your - targetSdkVersion to 22 It works for all
versions" - This works fine if you have not launched your app with
targetSdkVersion 23 yet.
If you already have launched your app with targetSdkVersion 23 then,
instead of adding compile 'com.github.traex.rippleeffect:library:1.3'
in dependancies, Download the project by clicking on link -
https://codeload.github.com/traex/RippleEffect/zip/master
Get library from that and use that in your app. It's probably gonna work :)

java.lang.IllegalArgumentException: No view found for id 0x7f0d00bf () for fragment

Error code show:
09-15 11:20:26.413 16914-16914/com.ats_school.bsdp E/AndroidRuntime:
FATAL EXCEPTION: main v
Process: com.ats_school.bsdp, PID: 16914
java.lang.IllegalArgumentException: No view found for id 0x7f0d00bf
(com.ats_school.bsdp:id/mission_menu) for fragment
MissionParty{6ecf0ff #0 id=0x7f0d00bf}
at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1059)
at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at
android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at
android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at
android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
ActivityMain.java
public class MainActivity extends AppCompatActivity {
ActionBarDrawerToggle toggle;
// FragmentTransaction fragmentTransaction;
// private static ImageView daily_sounds, daily_news, daily_videos, songParty, gallery, notice, mission, policy, history;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//onClickImageButtonListener();
//onClickImageViewListener();
final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
//DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open, R.string.close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (!isNetworkAvailable()) {
//Create an alertdialog
AlertDialog.Builder Checkbuilder = new AlertDialog.Builder(MainActivity.this);
Checkbuilder.setIcon(R.drawable.about_us);
Checkbuilder.setTitle("Error!");
Checkbuilder.setMessage("Check Your Internet Connection");
//Builder Retry
} else {
// NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
// navigationView.setNavigationItemSelectedListener(this);
final NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem item) {
Log.d("Navigation", "selected" + item.getTitle());
drawerLayout.closeDrawers();
getSupportActionBar().setTitle(item.getTitle());
switch (item.getItemId()) {
case R.id.mission_menu:
goToMissionMenu();
break;
case R.id.policy_menu:
goToPolicyMenu();
break;
}
return true;
}
});
}
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (toggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void goToMissionMenu() {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
MissionParty missionParty = new MissionParty();
transaction.replace(R.id.mission_menu, missionParty);
transaction.addToBackStack(null);
transaction.commit();
}
private void goToPolicyMenu() {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
PolicyMenu policyMenu = new PolicyMenu();
transaction.replace(R.id.policy_menu, policyMenu);
transaction.addToBackStack(null);
transaction.commit();
}
activity_main.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"
tools:context="com.ats_school.bsdp.MainActivity"
android:id="#+id/drawerLayout">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_container">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1"
android:shrinkColumns="1"
android:background="#color/white"
android:orientation="vertical"
tools:context="com.ats_school.bsdp.MainActivity">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layoutDirection="inherit"
android:padding="10dp"
>
<RelativeLayout
android:background="#color/white"
android:layout_height="150dp"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/daily_sounds"
android:src="#drawable/daily_news"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"/>
<TextView
android:text="#string/daily_sounds"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_below="#+id/daily_sounds"
android:textAllCaps="false"
android:textStyle="bold"
android:textColor="#color/pressed_green"
android:textSize="20dp"/>
</RelativeLayout>
<RelativeLayout
android:background="#color/white"
android:layout_height="150dp"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/daily_news"
android:src="#drawable/news"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"/>
<TextView
android:text="#string/daily_news"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_below="#+id/daily_news"
android:textAllCaps="false"
android:textStyle="bold"
android:textColor="#color/pressed_green"
android:textSize="20dp"/>
</RelativeLayout>
<RelativeLayout
android:background="#color/white"
android:layout_height="150dp"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/daily_videos"
android:src="#drawable/videos"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"/>
<TextView
android:text="#string/daily_videos"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_below="#+id/daily_videos"
android:textAllCaps="false"
android:textStyle="bold"
android:textColor="#color/pressed_green"
android:textSize="20dp"/>
</RelativeLayout>
</TableRow>
</FrameLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#menu/nav_menu"
app:itemBackground="#drawable/pressed_green"
android:layout_gravity="start"
android:id="#+id/navigationView">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
MissionParty.java (Fragment file)
public class MissionParty extends Fragment {
// TODO: Rename parameter arguments, choose names that match
public MissionParty() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_mission_party, container, false);
}
}

Activity is hidden by fragment, it is not useable

i have builded an app that works perfectly on android with api higer than 21. The problem is that this instruction of my code:
mFragmentTransaction.replace(R.id.content_frame, new TabFragment()).commit();
Works in different way on API less then 21.
On Api less then 21 the new fragment hide the previus activity, so that i can't click on my Floating Action Button.
Here are two images that explain in abetter way my problem.
API HIGER THAN 21
API LESS THAN 21
So my question is: How can i have the same result in API less then 21 that i have on API Higer then 21?
Here is the affected part of the Main Activity Code:
public class MainActivity extends AppCompatActivity {
public static AppDataBase appDataBase;
public static UserDataBase userDataBase;
static FragmentManager mFragmentManager;
static FragmentTransaction mFragmentTransaction;
private DrawerLayout myDrawerLayout;
final String TXT_MAINACTVT_USER_HAVE_NOT_ADDED_CONSOLE = "Add a console!";
TextView currentConsole;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appDataBase = new AppDataBase(this);
userDataBase = new UserDataBase(this);
myDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
currentConsole = (TextView) findViewById(R.id.txt_Mainactvt_currentConsole);
currentConsole.setText(TXT_MAINACTVT_USER_HAVE_NOT_ADDED_CONSOLE);
tabLayoutManagement();
floatingActionButtonManagement();
leftDrawerMenuManagement();
rigthDrawerMenuManagement();
populateMyConsole();
}
void tabLayoutManagement() {
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.content_frame, new TabFragment()).commit();
}
// Floating Action Button
private void floatingActionButtonManagement() {
FloatingActionButton fab_addGame = (FloatingActionButton)findViewById(R.id.fab_AddGame);
fab_addGame.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
/*
The currentConsole TextView is used to show at the user wich console is selected.
We use it to have a strng that conteins the selected console.
Call the method that manage the click event of the FloatingActionButton. We pass the console name.
*/
String currentConsoleName = currentConsole.getText().toString();
floatingActionButtonClickEvent(currentConsoleName);
}
});
}
private void floatingActionButtonClickEvent(String currentConsoleName) {
/*
Check if user have added a console. If he did start a menu for adding games, else start an
error message
*/
if (!currentConsoleName.equals(TXT_MAINACTVT_USER_HAVE_NOT_ADDED_CONSOLE)) {
popUpViewAddGameBuild(currentConsoleName);
}
else
mySimpleAlertDialogMethod("Attention!", "Before you enter game, you must enter a console.", true, true);
}
private void popUpViewAddGameBuild(String currentConsoleName) {
/*
Build the view that show the menu for adding games.
*/
LayoutInflater inflater = this.getLayoutInflater();
View popupView = inflater.inflate(R.layout.popupview_addgame, null);
PopupWindow popupWindow = new PopupWindow(
popupView,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT);
popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
popupWindow.setFocusable(true);
popupWindow.showAtLocation(popupView, 0, 0, 0);
}
Here is the TabLayout Class:
public class TabFragment extends Fragment {
public static TabLayout tabLayout;
public static ViewPager viewPager;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View x = inflater.inflate(R.layout.tab_layout, null);
tabLayout = (TabLayout) x.findViewById(R.id.tabs);
viewPager = (ViewPager) x.findViewById(R.id.viewpager);
viewPager.setAdapter(new MyAdapter(getChildFragmentManager()));
tabLayout.post(new Runnable() {
#Override
public void run() {
tabLayout.setupWithViewPager(viewPager);
}
});
return x;
}
public class MyAdapter extends FragmentPagerAdapter {
public int position;
public MyAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position){
case 0 :
return new DesireFragment();
case 1 :
return new BuyedFragment();
case 2 :
return new StartedFragment();
case 3 :
return new FinishedFragment();
case 4 :
return new AllTrophiesFragment();
}
return null;
}
#Override
public int getCount() {
return 5;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0 :
return "Desire";
case 1 :
return "Buyed";
case 2 :
return "Started";
case 3 :
return "Finished";
case 4 :
return "AllTrophies";
}
return null;
}
}
}
There is the layout of the MainActivity:
<LinearLayout
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:fitsSystemWindows="true"
android:layout_gravity="end"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:id="#+id/toolbar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:navigationIcon="#drawable/ic_menu_white_24dp"
app:title="MyGames">
<Button
android:id="#+id/btnOpenRigthDrawer"
android:background="#drawable/ic_filter_list_white_24dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:layout_gravity="right" />
<Button
android:id="#+id/btnOpenOptions"
android:background="#drawable/ic_settings_white_24dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="17dp"
android:layout_gravity="right" />
</android.support.v7.widget.Toolbar>
</RelativeLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollIndicators="bottom">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:backgroundTint="#color/colorPrimary"
app:borderWidth="0dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/txt_Mainactvt_currentConsole"
android:layout_gravity="center_horizontal|top"
android:layout_marginTop="50dp"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_AddGame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="17dp"
android:layout_marginRight="17dp"
android:src="#drawable/ic_mode_edit_white_24dp"
android:layout_gravity="bottom|right"
android:background="#color/colorPrimary" />
</FrameLayout>
<include
layout="#layout/drawer_left"
android:id="#+id/layLeft"
android:layout_gravity="start"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
<include
layout="#layout/drawer_rigth"
android:id="#+id/layRigth"
android:layout_gravity="end"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:scrollbars="vertical"
/>
</android.support.v4.widget.DrawerLayout>
And here is the layout code of the TabLayout:
<?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:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
app:tabGravity="fill"
app:tabMode="scrollable"
android:background="#color/colorPrimary"
app:tabIndicatorColor="#android:color/holo_orange_dark"
app:tabSelectedTextColor="#android:color/holo_orange_dark"
app:tabTextColor="#android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
You replace the content of your FrameLayout with an Fragment. this leads to your strange result.
Add a Layout to your Framelayout instead and use it as your FragmentContainer:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:backgroundTint="#color/colorPrimary"
app:borderWidth="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_frame"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/txt_Mainactvt_currentConsole"
android:layout_gravity="center_horizontal|top"
android:layout_marginTop="50dp"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_AddGame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="17dp"
android:layout_marginRight="17dp"
android:src="#drawable/ic_mode_edit_white_24dp"
android:layout_gravity="bottom|right"
android:background="#color/colorPrimary" />
</FrameLayout>
Try to place your FrameLayout with this button to the end of layout

Categories