Bottom navigation bar: When try to replace the current fragment with button outside of nav bar it puts it on...
so I'm working on a group android project and one of the guys on my team used https://github.com/aurelhubert/ahbottomnavigation. We're all new to android so he doesn't really understand what it's doing and neither do I. It doesn't look like it's using a fragment transaction to switch back and forth between the tabs, which is confusing me.
Essentially my problem is one of the tabs on the bottom nav bar is my home page and I created a button on there to send me to another fragment for the user's profile.
ImageButton profileButton = (ImageButton) rootView.findViewById(R.id.profile_button);
profileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.coordinator, new ProfileFragment());
fragmentTransaction.commit();
}
});
But this doesn't replace the current fragment at all but just puts it on top. Then the profile fragment stays on top even if you use the bottom nav bar to switch to another frag.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
>
<ImageButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/ic_profile"
android:background="@null"
android:id="@+id/profile_button"
/>
<include
layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
And then content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.william.homepage.MainActivity"
tools:showIn="@layout/activity_main">
<com.dinuscxj.progressbar.CircleProgressBar
android:id="@+id/custom_progress5"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="25dp"
android:gravity="center"
app:progress_background_color="@color/holo_darker_gray"
app:progress_end_color="@color/holo_green_light"
app:progress_start_color="@color/holo_green_light"
app:progress_stroke_width="10dp"
app:progress_text_color="@color/holo_green_light"
app:progress_text_size="40dp"
app:style="solid_line" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp" />
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="60sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Total Steps"
android:textSize="30sp"
android:visibility="visible" />
<Button
android:id="@+id/logout_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout" />
</LinearLayout>
And then activity_main.xml. I originally tried the replace with R.id.viewpager but then the current home fragment does disappear but the profile fragment does not so it's just a blank screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.AppBarLayout>
<edu.umd.arturomcgill.healcity.NoSwipePager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:background="#EFEFEF"/>
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</android.support.design.widget.CoordinatorLayout>
If someone could tell me where I'm going wrong and how to get the profile fragment to show up, I would really, really appreciate it. Thanks!
add a comment |
so I'm working on a group android project and one of the guys on my team used https://github.com/aurelhubert/ahbottomnavigation. We're all new to android so he doesn't really understand what it's doing and neither do I. It doesn't look like it's using a fragment transaction to switch back and forth between the tabs, which is confusing me.
Essentially my problem is one of the tabs on the bottom nav bar is my home page and I created a button on there to send me to another fragment for the user's profile.
ImageButton profileButton = (ImageButton) rootView.findViewById(R.id.profile_button);
profileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.coordinator, new ProfileFragment());
fragmentTransaction.commit();
}
});
But this doesn't replace the current fragment at all but just puts it on top. Then the profile fragment stays on top even if you use the bottom nav bar to switch to another frag.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
>
<ImageButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/ic_profile"
android:background="@null"
android:id="@+id/profile_button"
/>
<include
layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
And then content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.william.homepage.MainActivity"
tools:showIn="@layout/activity_main">
<com.dinuscxj.progressbar.CircleProgressBar
android:id="@+id/custom_progress5"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="25dp"
android:gravity="center"
app:progress_background_color="@color/holo_darker_gray"
app:progress_end_color="@color/holo_green_light"
app:progress_start_color="@color/holo_green_light"
app:progress_stroke_width="10dp"
app:progress_text_color="@color/holo_green_light"
app:progress_text_size="40dp"
app:style="solid_line" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp" />
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="60sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Total Steps"
android:textSize="30sp"
android:visibility="visible" />
<Button
android:id="@+id/logout_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout" />
</LinearLayout>
And then activity_main.xml. I originally tried the replace with R.id.viewpager but then the current home fragment does disappear but the profile fragment does not so it's just a blank screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.AppBarLayout>
<edu.umd.arturomcgill.healcity.NoSwipePager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:background="#EFEFEF"/>
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</android.support.design.widget.CoordinatorLayout>
If someone could tell me where I'm going wrong and how to get the profile fragment to show up, I would really, really appreciate it. Thanks!
add a comment |
so I'm working on a group android project and one of the guys on my team used https://github.com/aurelhubert/ahbottomnavigation. We're all new to android so he doesn't really understand what it's doing and neither do I. It doesn't look like it's using a fragment transaction to switch back and forth between the tabs, which is confusing me.
Essentially my problem is one of the tabs on the bottom nav bar is my home page and I created a button on there to send me to another fragment for the user's profile.
ImageButton profileButton = (ImageButton) rootView.findViewById(R.id.profile_button);
profileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.coordinator, new ProfileFragment());
fragmentTransaction.commit();
}
});
But this doesn't replace the current fragment at all but just puts it on top. Then the profile fragment stays on top even if you use the bottom nav bar to switch to another frag.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
>
<ImageButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/ic_profile"
android:background="@null"
android:id="@+id/profile_button"
/>
<include
layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
And then content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.william.homepage.MainActivity"
tools:showIn="@layout/activity_main">
<com.dinuscxj.progressbar.CircleProgressBar
android:id="@+id/custom_progress5"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="25dp"
android:gravity="center"
app:progress_background_color="@color/holo_darker_gray"
app:progress_end_color="@color/holo_green_light"
app:progress_start_color="@color/holo_green_light"
app:progress_stroke_width="10dp"
app:progress_text_color="@color/holo_green_light"
app:progress_text_size="40dp"
app:style="solid_line" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp" />
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="60sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Total Steps"
android:textSize="30sp"
android:visibility="visible" />
<Button
android:id="@+id/logout_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout" />
</LinearLayout>
And then activity_main.xml. I originally tried the replace with R.id.viewpager but then the current home fragment does disappear but the profile fragment does not so it's just a blank screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.AppBarLayout>
<edu.umd.arturomcgill.healcity.NoSwipePager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:background="#EFEFEF"/>
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</android.support.design.widget.CoordinatorLayout>
If someone could tell me where I'm going wrong and how to get the profile fragment to show up, I would really, really appreciate it. Thanks!
so I'm working on a group android project and one of the guys on my team used https://github.com/aurelhubert/ahbottomnavigation. We're all new to android so he doesn't really understand what it's doing and neither do I. It doesn't look like it's using a fragment transaction to switch back and forth between the tabs, which is confusing me.
Essentially my problem is one of the tabs on the bottom nav bar is my home page and I created a button on there to send me to another fragment for the user's profile.
ImageButton profileButton = (ImageButton) rootView.findViewById(R.id.profile_button);
profileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.coordinator, new ProfileFragment());
fragmentTransaction.commit();
}
});
But this doesn't replace the current fragment at all but just puts it on top. Then the profile fragment stays on top even if you use the bottom nav bar to switch to another frag.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
>
<ImageButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/ic_profile"
android:background="@null"
android:id="@+id/profile_button"
/>
<include
layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
And then content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.william.homepage.MainActivity"
tools:showIn="@layout/activity_main">
<com.dinuscxj.progressbar.CircleProgressBar
android:id="@+id/custom_progress5"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="25dp"
android:gravity="center"
app:progress_background_color="@color/holo_darker_gray"
app:progress_end_color="@color/holo_green_light"
app:progress_start_color="@color/holo_green_light"
app:progress_stroke_width="10dp"
app:progress_text_color="@color/holo_green_light"
app:progress_text_size="40dp"
app:style="solid_line" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp" />
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="60sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Total Steps"
android:textSize="30sp"
android:visibility="visible" />
<Button
android:id="@+id/logout_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout" />
</LinearLayout>
And then activity_main.xml. I originally tried the replace with R.id.viewpager but then the current home fragment does disappear but the profile fragment does not so it's just a blank screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.AppBarLayout>
<edu.umd.arturomcgill.healcity.NoSwipePager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:background="#EFEFEF"/>
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</android.support.design.widget.CoordinatorLayout>
If someone could tell me where I'm going wrong and how to get the profile fragment to show up, I would really, really appreciate it. Thanks!
asked Nov 24 '18 at 5:55
Cinn MCinn M
116
116
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455561%2fbottom-navigation-bar-when-try-to-replace-the-current-fragment-with-button-outs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455561%2fbottom-navigation-bar-when-try-to-replace-the-current-fragment-with-button-outs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown