Error FrameLayout in android 6 But not library [duplicate] - java

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 :)

Related

Issues with Android Soft Keyboard and panAdjust

I am trying to achieve similar effect to the one found in Todoits application where you can click on FAB and it shows a floating popup for adding new task.
This is how it looks:
The closest to it I managed to achieve is this:
It is nearly there, but I want the popup to be about 10dp above the keyboard and scroll the recycle viewer to the last item but I can't get it there :/ Currently, the popup is centred.
I have tried before adding the popup to the bottom of the screen and setting android:windowSoftInputMode="adjustResize" but this was moving my bottom navigation above the keyboard too. Setting windowsSoftInputMode to panAdjust was cutting away the toolbar and few items from the list.
Have you got any suggestions about how to achieve similar effect to the one in Todoist? Maybe with a DialogFragment?
Below is my current code (navigation bar implementation is still not completed):
MainActivity:
public class MainActivity extends AppCompatActivity {
private WorkoutsListFragment workoutsListFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
ActionBar actionBar = getSupportActionBar();
this.workoutsListFragment = new WorkoutsListFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.main_layout, workoutsListFragment)
.commit();
}
}
WorkoutListFragment:
public class WorkoutsListFragment extends Fragment
implements View.OnClickListener, WorkoutListViewHolderInterface {
private RecyclerView recyclerView;
private WorkoutListRecycleViewAdapter recycleViewAdapter;
private AddBoxView addBoxView;
private FloatingActionButton actionButton;
private InputMethodManager imm;
private WorkoutViewModel workoutViewModel;
private boolean addBoxStatus;
public WorkoutsListFragment() {}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.addBoxStatus = false;
//Irrelevant code removed (Dagger 2 DI)
this.workoutViewModel =
ViewModelProviders.of(this, workoutViewModelFactory).get(WorkoutViewModel.class);
workoutViewModel.init(7);
workoutViewModel.getWorkout().observe(this, w -> this.updateWorkoutsList(w, false));
this.imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
}
#Override
public View onCreateView(
#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_workouts_list, container, false);
this.recyclerView = view.findViewById(R.id.workoutsList);
// this.recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager recyclerViewLayoutManager = new LinearLayoutManager(getContext());
this.recyclerView.setLayoutManager(recyclerViewLayoutManager);
this.recycleViewAdapter = new WorkoutListRecycleViewAdapter(this);
this.recyclerView.setAdapter(recycleViewAdapter);
this.actionButton = view.findViewById(R.id.floating_action_add_workout);
this.actionButton.setOnClickListener(this);
this.addBoxView = new AddBoxView(Objects.requireNonNull(getContext()));
FrameLayout.LayoutParams addBoxLayoutParams =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER);
this.addBoxView.setLayoutParams(addBoxLayoutParams);
this.addBoxView.getButton().setOnClickListener(this);
return view;
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.floating_action_add_workout:
this.addBoxView((FrameLayout) v.getParent(), v);
break;
case R.id.overlay_layout:
removeAddBoxView((FrameLayout) v);
break;
case R.id.button:
this.addNewWorkout(this.addBoxView.getInputText());
break;
}
}
//Irrelevant code removed....
private void addBoxView(FrameLayout viewGroup, View v) {
this.addBoxStatus = true;
viewGroup.setClickable(true);
viewGroup.setOnClickListener(this);
viewGroup.setBackgroundColor(
getResources().getColor(R.color.cardview_shadow_start_color, null));
viewGroup.removeView(v);
viewGroup.addView(this.addBoxView);
this.addBoxView.requestInputFocus();
this.imm.showSoftInput(this.addBoxView.getInput(), InputMethodManager.SHOW_IMPLICIT);
}
private void removeAddBoxView(FrameLayout viewGroup) {
viewGroup.setClickable(false);
this.imm.hideSoftInputFromWindow(this.addBoxView.getInput().getWindowToken(), 0);
viewGroup.removeView(this.addBoxView);
viewGroup.setBackgroundColor(getResources().getColor(R.color.cardview_shadow_end_color, null));
viewGroup.addView(this.actionButton);
this.addBoxStatus = false;
}
}
Fragment_workouts_list layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="#e1e1e1"
android:padding="0dp"
tools:context=".Activities.MainActivity.Fragments.Workouts.WorkoutsListFragment"
tools:layout_editor_absoluteY="81dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/workoutsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:elevation="0dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toTopOf="#+id/add_box_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.RecyclerView>
<FrameLayout
android:id="#+id/overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:outlineProvider="bounds">
<android.support.design.widget.FloatingActionButton
android:id="#+id/floating_action_add_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="40dp"
android:layout_marginEnd="40dp"
android:clickable="true"
android:src="#android:color/holo_blue_dark" />
</FrameLayout>
</FrameLayout>
MainActivity Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="#+id/root_view"
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_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/AppTheme.AppBar" />
<FrameLayout
android:id="#+id/main_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar">
</FrameLayout>
<android.support.design.widget.BottomNavigationView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#color/colorPrimary"
android:foregroundGravity="bottom"
android:visibility="visible"
app:itemTextColor="#color/textColorWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/my_navigation_items" />
</android.support.constraint.ConstraintLayout>

Show google map with drawer

We have different differnet activities of google map ( Some with tabs, Some simple, And some other activities), So we are are trying to implement navigation drawer in our app, For this we created a class which extend ActionBarActivity and has drawer, And we are extending this main activity in our classes for navigation drawer, But when we open our application its showing map is null.
Please help.
Here is our files
drawerlist.xml
<?xml version="1.0" encoding="utf-8"?>
<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.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="#FA0"
android:id="#+id/toolbar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="#+id/shitstuff"
app:itemTextColor="#000"
app:menu="#layout/drawermenu"
android:layout_marginTop="-24dp"
/>
</android.support.v4.widget.DrawerLayout>
mapload.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffc17540"
android:id="#+id/maptab"
>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="fill_parent"
android:gravity="bottom"
android:layout_height="fill_parent"
/>
<RelativeLayout
android:id="#+id/slidingContainer"
android:layout_width="fill_parent"
android:gravity="bottom"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/t"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffff773c"
android:orientation="horizontal">
<RadioGroup
android:id="#+id/rg_views"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<RadioButton
android:id="#+id/rb_normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/str_rb_normal"
android:checked="true" />
<RadioButton
android:id="#+id/rb_satellite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/str_rb_satellite" />
<RadioButton
android:id="#+id/rb_terrain"
android:layout_width="161dp"
android:layout_height="wrap_content"
android:text="#string/str_rb_terrain" />
</RadioGroup>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/inhorizontalscrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:src="#android:drawable/ic_input_add" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
<View
android:id="#+id/transparentView"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="#dimen/map_height"
android:layout_alignParentTop="true"/>
</RelativeLayout>
</RelativeLayout>
BaseActivity.java
public class BaseActivity extends ActionBarActivity
{
public DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_list);
// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);
// You were missing this setHomeAsUpIndicator
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_navigation_drawer);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView n = (NavigationView) findViewById(R.id.shitstuff);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout , R.string.drawer_open, R.string.drawer_close)
{
/*
* Called when a drawer has settled in a completely closed state
*/
public void onDrawerClosed(View view)
{
Log.d("drawerToggle", "Drawer closed");
super.onDrawerClosed(view);
// getActionBar().setTitle(R.string.app_name);
invalidateOptionsMenu(); //Creates call to onPrepareOptionsMenu()
}
/*
* Called when a drawer has settled in a completely open state
*/
public void onDrawerOpened(View drawerView)
{
Log.d("drawerToggle", "Drawer opened");
super.onDrawerOpened(drawerView);
// getActionBar().setTitle("NavigationDrawer");
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
n.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
////.......
}
mDrawerLayout.closeDrawers(); // CLOSE DRAWER
return true;
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// THIS IS YOUR DRAWER/HAMBURGER BUTTON
case android.R.id.home:
mDrawerLayout.openDrawer(GravityCompat.START); // OPEN DRAWER
return true;
}
return super.onOptionsItemSelected(item);
}
}
Mylocation.java
public class MyLocation extends BaseActivity implements View.OnClickListener,OnMapReadyCallback {
GoogleMap googleMap;
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.mapload, null, false); // line no-74
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
But everytime i run application i am getting this error
java.lang.RuntimeException: Unable to start activity ComponentInfo{MyLocation}: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at com.myapp.gps.MyLocation.onCreate(MyLocation.java:74) //error here
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7237) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
at com.myapp.gps.MyLocation.onCreate(MyLocation.java:74)  //error here
at android.app.Activity.performCreate(Activity.java:6876) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
What I tried:-
inflater.from(getApplicationContext()).inflate(R.layout.mapload, pageHolder, true);
GoogleMap mapFragment =((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); //getting null pointer exception here
another thing which I tried
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mapFragment).commit(); //same null pointer exception
The line with inflater.inflate is doing nothing useful there in that class. The XML layout isn't loaded and findFragmentById(R.id.map) is returning your null.
I think you wanted something like
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.mapload);
// Find fragment here
}
Or maybe you maybe you just wanted setContentView from the parent class?
Basically, the error is saying your <fragment> tag is missing a class.
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="fill_parent"
<!-- Needs a class or name attribute -->
android:gravity="bottom"
android:layout_height="fill_parent" />
For example, from the documentation
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
(Also worth mentioning that xmlns:android only is to be applied to the root xml element)
Though, I do not think you need a whole separate Activity or layout.
Load the map fragment into this FrameLayout
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
just like any regular Fragment...
SupportMapFragment mapFragment = new SupportMapFragment();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content, mapFragment)
.commit();
mapFragment.getMapAsync(this);
add this line to your xml:
android:name="com.google.android.gms.maps.SupportMapFragment"
like this:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="fill_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:gravity="bottom"
android:layout_height="fill_parent"/>
and the best way to implement google map with drawer is to use fragment, that's mean change your class "MyLocation" to extends from fragment

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

Open Navigation Drawer with layout on click event

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);
}

Categories