Does using a BottomBar prevent fragments from opening?

I use the support library to add a bottom panel that is similar to the material design. The bottom panel works fine, but it seems that if I get a panel, if I try to open any fragment from my user adapter, the fragment will not open ... or maybe it will open behind my main layout? I have no idea how to understand this. Below is my code.

I read more posts about SO and on the Internet, and I think this is because the fragment is loaded correctly, but below or next to the bottom panel ... and why is it not visible? Why is this happening? Is this because the bottom panel has LinearLayout? I defined it as a menu, so I'm not sure if I can control it as LinearLayout ....

Setting up the bottom panel, this method is called from onCreate of my activity:

public void setupBottomToolbar(Bundle savedInstanceState) { mBottomBar = BottomBar.attach(MainActivity.this, savedInstanceState); mBottomBar.setItems(R.menu.bottombar_menu); mBottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() { @Override public void onMenuTabSelected(@IdRes int menuItemId) { if (menuItemId == R.id.toolbar_jobs) { } else if (menuItemId == R.id.toolbar_messages) { } else if (menuItemId == R.id.toolbar_recentJobs) { } else if (menuItemId == R.id.toolbar_employerPools) { } } @Override public void onMenuTabReSelected(@IdRes int menuItemId) { if (menuItemId == R.id.toolbar_jobs) { // The user reselected item number one, scroll your content to top. } else if (menuItemId == R.id.toolbar_messages) { } else if (menuItemId == R.id.toolbar_employerPools) { } else if (menuItemId == R.id.toolbar_recentJobs) { } } }); // Setting colors for different tabs when there more than three of them. // You can set colors for tabs in three different ways as shown below. mBottomBar.getBar().setBackgroundColor(getResources().getColor(R.color.laborswipe_darkgray)); mBottomBar.setActiveTabColor(getResources().getColor(R.color.laborswipe_lightgray)); // Make a Badge for the second tab, with red background color and a value of "13". BottomBarBadge unreadMessages = mBottomBar.makeBadgeForTabAt(1, getResources().getColor(R.color.laborswipe_orange), 5); // Control the badge visibility unreadMessages.show(); //unreadMessages.hide(); // Change the displayed count for this badge. //unreadMessages.setCount(4); // Change the show / hide animation duration. unreadMessages.setAnimationDuration(200); // If you want the badge be shown always after unselecting the tab that contains it. unreadMessages.setAutoShowAfterUnSelection(true); // If you don't want this badge to be hidden after selecting the tab contains it. unreadMessages.setAutoShowAfterUnSelection(false); } 

In my adapter, I try to open a fragment when you click a button, for example:

 holder.desc.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(context, "Open Description", Toast.LENGTH_SHORT).show(); JobDescFragment firstFragment = new JobDescFragment(); ((MainActivity)context).getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, firstFragment).commit(); } }); 

If I comment on the setupBottomToolbar () call in my onCreate activity, the fragment opens fine ... but that means I don't have a bottom bar ...

What am I missing? There should be a way to use the bottom panel and also open a fragment?

Thanks!

EDIT:

Here is the top of my activity.

 public class MainActivity extends AppCompatActivity { private ArrayList<String> swipecardsList; private ArrayList<Job> jobList = new ArrayList<Job>(); private JobAdapter arrayAdapter; //arrayadapter private BottomBar mBottomBar; SharedPreferences settings; @InjectView(R.id.frame) SwipeFlingAdapterView flingContainer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Remove title bar //this.requestWindowFeature(Window.FEATURE_NO_TITLE); //color the notification bar with our company colors Window window = this.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(this.getResources().getColor(R.color.laborswipe_notificationbar)); //remove title from action bar and add the logo to the top left of the action bar setupTopToolbar(); setContentView(R.layout.activity_main); ButterKnife.inject(this); //set up the bottom toolbar using the roughike library to mimic android material design setupBottomToolbar(savedInstanceState); 

My adapter:

 public class JobAdapter extends ArrayAdapter<Job> { private final Context context; private final ArrayList<Job> jobs; private final int layoutResourceId; private final SwipeFlingAdapterView flingContainer; private boolean isExpanded = false; public JobAdapter(Context context, int layoutResourceId, ArrayList<Job> jobs, SwipeFlingAdapterView flingContainer) { super(context, layoutResourceId, jobs); this.context = context; this.jobs = jobs; this.layoutResourceId = layoutResourceId; this.flingContainer = flingContainer; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; final ViewHolder holder; String pay, hrs; final Bundle fragmentParams = new Bundle(); LayoutInflater inflater = LayoutInflater.from(context); if (view == null) { view = inflater.inflate(layoutResourceId, parent, false); holder = new ViewHolder(); holder.title = (TextView)view.findViewById(R.id.tv_jobTitle); holder.desc = (TextView) view.findViewById(R.id.tv_JobDesc); view.setTag(holder); } else { holder = (ViewHolder)view.getTag(); } Job j = jobs.get(position); holder.title.setText(j.getJobTitle()); holder.desc.setText(j.getDescription()); //when user clicks apply, swipe the card right holder.apply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Open up a fragment to display the entire job description Toast.makeText(context, "Applied", Toast.LENGTH_SHORT).show(); flingContainer.getTopCardListener().selectRight(); } }); //when user clicks dismiss, swipe the card left holder.dismiss.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Open up a fragment to display the entire job description Toast.makeText(context, "Dismissed", Toast.LENGTH_SHORT).show(); flingContainer.getTopCardListener().selectLeft(); } }); //on click event listener for the job description field - open larger window to read description holder.desc.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //Toast.makeText(context, "Open Description", Toast.LENGTH_SHORT).show(); JobDescFragment firstFragment = new JobDescFragment(); Fragment frag = new Fragment(); frag = firstFragment.newJobDescFrag(j.getDescription()); ((MainActivity) context).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, frag) .addToBackStack("JobDesc").commit(); } }); return view; } public class ViewHolder { TextView title; TextView payrate; TextView dateRange; TextView workinghrs; TextView location; TextView companyname; TextView desc; TextView experience; TextView equipment; Button apply, dismiss, expand; } } 

activity_main.xml:

 <merge 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"> <com.lorentzos.flingswipe.SwipeFlingAdapterView android:id="@+id/frame" android:background="@color/laborswipe_lightgray" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:context=".MainActivity" android:layout_gravity="top" /> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" /> </merge> 

Fragment Layout:

 <FrameLayout 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=".JobDescFragment"> <LinearLayout android:id="@+id/outerDescriptionLayout" android:layout_width="match_parent" android:layout_height="400dp" android:layout_gravity="center_horizontal|top" android:orientation="vertical" android:background="@drawable/swipecard_shadow" android:gravity="top" android:layout_marginLeft="5dp"> <LinearLayout android:id="@+id/DescriptionLayout" android:layout_width="match_parent" android:layout_height="400dp" android:layout_gravity="center_horizontal|top" android:orientation="vertical" android:weightSum="1" android:gravity="top" android:layout_marginTop="20dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="#00FF00" android:clickable="true"> <TextView android:layout_width="200dp" android:layout_height="200dp" android:text="Detailed Description:" android:textColor="#000000" android:id="@+id/tv_title" /> <TextView android:layout_width="200dp" android:layout_height="200dp" android:text="THIS IS THE FULL DESCRIPTION" android:textColor="#000000" android:id="@+id/tv_fullDescription" /> </LinearLayout> </LinearLayout> </FrameLayout> 

Logcat:

 08-07 11:20:47.799 13896-13896/com.lorentzos.swipecards.example I/System.out: DEBUG: job desc fragment loaded! 08-07 11:20:47.855 13896-13941/com.lorentzos.swipecards.example W/EGL_emulation: eglSurfaceAttrib not implemented 08-07 11:20:47.855 13896-13941/com.lorentzos.swipecards.example W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaaa7f880, error=EGL_SUCCESS 08-07 11:20:48.002 13896-13941/com.lorentzos.swipecards.example V/RenderScript: 0xa1408000 Launching thread(s), CPUs 2 08-07 11:20:49.798 13896-13941/com.lorentzos.swipecards.example E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae433ca0 

When I use the bottom panel (doesn't work - not a single fragment is open, but a toast is displayed):

enter image description here

When I do not use the bottom panel (the working fragment is open, the background is green):

enter image description here

+7
java android android-layout android-fragments android-support-library
source share
2 answers

try to connect the problem with the problem and without problems (no node), and since you are using merge , the layout hierarchy will be removed according to your activity's viewgroup (linear, relative) constraints (we don’t know what they are).

as you said, when there is no insignificance , you fragment is displayed perfectly , although when it is in it, the statistics of the problem, according to your log fragment indicating that your fragment is fully loaded, even if there is a middle fragment when detecting visibility in a bottleneck but not displayed, it seems that your fragment did not get the appropriate space to display.

another solution might add a lower bar to your fragment instead of activity to avoid overlapping e.g.

 mBottomBar.attach(findViewById(R.id.fragmentContainer), savedInstanceState); 
+1
source share

Well, I think the solution for this should be simple, from what I see in your code, you attach the BottomBar to your activity, I think this is a problem. If you read readme.md on the gigub page on the roughike / BottomBar page, you will find this

Why does this block my navigation box?

All you need to do is not to attach the BottomBar to your activity, attach it to the view containing your content. For example, if your fragments are in a ViewGroup with idContainer, you should do something like this: mBottomBar.attach(findViewById(R.id.fragmentContainer), savedInstanceState);

So, since the navigation box works with the transition of the fragment inside and out with the animation, the same thing happens when you add a new fragment to your activity.

Decision

From what I see in your code, the fragment container id is: fragment_container in your action layout. So according to the documentation, you just need to connect your lower bit to fragment_container instead of MainActivity.this

 mBottomBar.attach(findViewById(R.id.fragment_container), savedInstanceState); 

If this does not work, try

What you need to do is add an extra FrameLayout to hold your node, which has a transparent background but sits on top of your fragment.

So change the main_activity layout to

 <merge 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"> <com.lorentzos.flingswipe.SwipeFlingAdapterView android:id="@+id/frame" android:background="@color/laborswipe_lightgray" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:context=".MainActivity" android:layout_gravity="top" /> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" /> <FrameLayout android:id="@+id/holder_bottombar" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent"/> </merge> 

Now in the code, instead of attaching the bottom panel to mainactivity, just attach it to the holder so

 mBottomBar.attach(findViewById(R.id.holder_bottombar), savedInstanceState); 
0
source share

All Articles