2017-09-12 2 views
0

Je veux montrer de fragment et snackbar mise en page XML va comme cecine se présente pas Snack-bar avec le fragment et la mise en page swiperefresh

activity_main.xml

<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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/snackbar_holder" 
    tools:context=".MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.NoActionBar.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:contentInsetEnd="0dp" 
      app:contentInsetLeft="0dp" 
      app:contentInsetRight="0dp" 
      app:contentInsetStart="0dp" 
      app:contentInsetStartWithNavigation="0dp" 
      app:layout_scrollFlags="scroll|enterAlways|snap" 
      app:popupTheme="@style/AppTheme.NoActionBar.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_main" /> 

    <com.github.clans.fab.FloatingActionButton 
     android:id="@+id/fab_refresh" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right|bottom" 
     android:layout_marginBottom="108dp" 
     android:layout_marginRight="8dp" 
     android:src="@drawable/ic_refresh" 
     app:fab_colorNormal="@color/white" 
     app:fab_colorPressed="@color/greyLight" 
     app:fab_colorRipple="@color/grey_dull" 
     app:fab_hideAnimation="@anim/scale_down" 
     app:fab_showAnimation="@anim/scale_up" 
     app:fab_size="mini" /> 
    <View 
     android:id="@+id/separator" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@color/white_like_bg_darker" 
     app:layout_anchor="@+id/bnv_section_selector" 
     app:layout_anchorGravity="top" /> 

    <android.support.design.widget.BottomNavigationView 
     android:id="@+id/bnv_section_selector" 
     android:layout_width="match_parent" 
     android:layout_height="56dp" 
     android:layout_gravity="bottom" 
     app:itemBackground="@color/white" 
     app:itemIconTint="@drawable/bottom_navigation_selector" 
     app:itemTextColor="@drawable/bottom_navigation_selector" 
     app:menu="@menu/bottom_navigation_main" /> 

</android.support.design.widget.CoordinatorLayout> 

content_main.xml

<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:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".MainActivity" 
    tools:showIn="@layout/app_bar_main"> 


</FrameLayout> 

Le fragment est gonflé dans FrameLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white_like_bg"> 

    <RelativeLayout 
     android:id="@+id/swipe_view_holder" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <HorizontalScrollView 
      android:id="@+id/buttonLayout" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/strip_height_price" 
      android:layout_alignParentTop="true" 
      android:layout_marginBottom="1dp" 
      android:background="@color/white_like_bg" 
      android:scrollbars="none"> 

      <LinearLayout 
       android:id="@+id/strip" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center_vertical" 
       android:orientation="horizontal" /> 


     </HorizontalScrollView> 

     <View 
      android:id="@+id/shadow" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/element_padding" 
      android:layout_below="@+id/buttonLayout" 
      android:background="@drawable/shadown" /> 


     <RelativeLayout 
      android:id="@+id/ll_filter_result" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/white" 
      android:gravity="center_vertical" 
      android:orientation="horizontal" 
      android:visibility="gone"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_margin="8dp" 
       android:layout_toLeftOf="@+id/iv_cross" 
       android:text="Filtered Results" /> 

      <ImageView 
       android:id="@+id/iv_cross" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:background="?attr/selectableItemBackground" 
       android:padding="4dp" 
       android:src="@drawable/ic_close" /> 
     </RelativeLayout> 
    </RelativeLayout> 

    <RadioGroup 
     android:id="@+id/rg_logistics_selector" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/swipe_view_holder" 
     android:layout_centerHorizontal="true" 
     android:orientation="horizontal" 
     android:visibility="gone"> 

     <RadioButton 
      android:id="@+id/rb_logistics_tab_1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:background="@drawable/checkable_bg_selector" 
      android:button="@null" 
      android:paddingBottom="8dp" 
      android:paddingLeft="16dp" 
      android:paddingRight="16dp" 
      android:paddingTop="8dp" 
      android:text="@string/iron_ore" 
      android:textColor="@color/checkable_text_color_selector" /> 

     <RadioButton 
      android:id="@+id/rb_logistics_tab_2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:background="@drawable/checkable_bg_selector" 
      android:button="@null" 
      android:paddingBottom="8dp" 
      android:paddingLeft="16dp" 
      android:paddingRight="16dp" 
      android:paddingTop="8dp" 
      android:text="@string/coal" 
      android:textColor="@color/checkable_text_color_selector" /> 

     <RadioButton 
      android:id="@+id/rb_logistics_tab_3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:background="@drawable/checkable_bg_selector" 
      android:button="@null" 
      android:paddingBottom="8dp" 
      android:paddingLeft="16dp" 
      android:paddingRight="16dp" 
      android:paddingTop="8dp" 
      android:text="@string/met_coke" 
      android:textColor="@color/checkable_text_color_selector" /> 

    </RadioGroup> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/rg_logistics_selector"> 

     <android.support.v4.widget.SwipeRefreshLayout 
      android:id="@+id/swipeContainer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="top"> 


      <se.emilsjolander.stickylistheaders.StickyListHeadersListView 
       android:id="@+id/listview" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="@dimen/head_padding" 
       android:layout_marginRight="@dimen/head_padding" 
       android:layout_marginTop="@dimen/head_padding" 
       android:clipToPadding="false" 
       android:nestedScrollingEnabled="true" 
       android:paddingBottom="@dimen/row_height" 
       android:visibility="visible" /> 
     </android.support.v4.widget.SwipeRefreshLayout> 

     <TextView 
      android:id="@+id/message_textview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/white" 
      android:clickable="true" 
      android:gravity="center" 
      android:padding="@dimen/outer_padding" 
      android:textColor="@color/text_grey" 
      android:textSize="@dimen/textSizeHighlight" 
      android:visibility="gone" /> 

     <RelativeLayout 
      android:id="@+id/progresslayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/white" 
      android:clickable="true" 
      android:visibility="gone"> 

      <ProgressBar 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" /> 
     </RelativeLayout> 


    </FrameLayout> 

</RelativeLayout> 

J'ai ajouté snack-bar. Mais ça ne se montre pas. Voici ce code que je l'ai utilisé pour montrer snackbar

View parent = getActivity().findViewById(R.id.snackbar_holder); 
      Snackbar.make(parent, 
        "Seems you are logged out", BaseTransientBottomBar.LENGTH_LONG).show(); 

Même j'ai essayé de le montrer dans MainActivity lui-même, mais pas de chance ... Suis-je manque quelque chose?

Répondre

0

essayer cette

CoordinatorLayout parent = (CoordinatorLayout)getActivity().findViewById(R.id.snackbar_holder) 
Snackbar snackbar = Snackbar.make(parent , "Seems you are logged out", Snackbar.LENGTH_SHORT); 
    View sbView = snackbar.getView(); 
    TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); 
    textView.setTextColor(Color.YELLOW); 
    snackbar.show(); 
+0

Essayé. Ne fonctionne pas BTW question est de ne pas montrer de casse-croûte du tout. Ce n'est pas comme si je ne suis pas en mesure de voir le texte ou quoi que ce soit – Bhupesh

0

depuis votre mise en page de parent est CoordinatorLayout montrer que vous devez snackbar initialiser CoordinatorLayout premier

CoordinatorLayout coordinatorlayout = (CoordinatorLayout)view.findViewById(R.id.snackbar_holder) 
Snackbar.make(coordinatorlayout, "Had a snack at Snackbar", Snackbar.LENGTH_LONG).show(); 
+0

Merci pour la réponse, mais il n'a pas résolu le problème – Bhupesh