FloatingActionButton doesn't start invisible - java

I want to do a FAB which is opening 2 other FABs to left after clicking. But it doesn't start invisibled. I used all way in those codelines but It doesn't work. (ScaleX-Y = 0, android:invisibility, setInvisibility etc..)
DersActivity.java
private Boolean isFabOpen = false;
private FloatingActionButton fab_ders, fab_ders_ara, fab_ders_ekle;
private Animation fab_open, fab_close, rotate_forward, rotate_backward;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
...
fab_ders = (FloatingActionButton) findViewById(R.id.fab_ders);
fab_ders_ara = (FloatingActionButton) findViewById(R.id.fab_ders_ara);
fab_ders_ekle = (FloatingActionButton) findViewById(R.id.fab_ders_ekle);
fab_open = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_open_ders);
fab_close = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_close_ders);
rotate_forward = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_forward);
rotate_backward = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_backward);
fab_ders.setOnClickListener(this);
fab_ders_ara.setOnClickListener(this);
fab_ders_ekle.setOnClickListener(this);
...
...
}
#Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.fab_ders:
animateFAB();
break;
case R.id.fab_ders_ara:
Log.d("Test", "Fab 1");
break;
case R.id.fab_ders_ekle:
Log.d("Test", "Fab 2");
break;
}
}
public void animateFAB() {
if (isFabOpen) {
fab_ders.startAnimation(rotate_backward);
fab_ders_ara.startAnimation(fab_close);
fab_ders_ekle.startAnimation(fab_close);
fab_ders_ara.setClickable(false);
fab_ders_ekle.setClickable(false);
isFabOpen = false;
Log.d("Test", "close");
} else {
fab_ders.startAnimation(rotate_forward);
fab_ders_ara.startAnimation(fab_open);
fab_ders_ekle.startAnimation(fab_open);
fab_ders_ara.setClickable(true);
fab_ders_ekle.setClickable(true);
isFabOpen = true;
Log.d("Test", "open");
}
}
I used Animation in this file but It doesn't matter to problem.
activity_ders.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
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:fitsSystemWindows="true"
tools:openDrawer="start">
<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:fitsSystemWindows="true"
tools:context=".DersActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:elevation="5dp"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:elevation="5dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<include layout="#layout/tool_bar2"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_ders"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_ders_ekle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/fab2_margin"
android:src="#drawable/ic_add_circle_white_24dp"
android:visibility="gone"
app:backgroundTint="#color/colorFAB2"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:fabSize="mini"
android:scaleX="0.0"
android:scaleY="0.0"
android:alpha="0.0"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_ders_ara"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/fab1_margin"
android:src="#drawable/ic_search_white_24dp"
android:visibility="gone"
app:backgroundTint="#color/colorFAB2"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:fabSize="mini"
android:scaleX="0.0"
android:scaleY="0.0"
android:alpha="0.0"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_ders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add"
app:backgroundTint="#color/colorFAB2"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"/>
</android.support.design.widget.CoordinatorLayout>
<include layout="#layout/nav_view"/>
</android.support.v4.widget.DrawerLayout>
This is what I'm trying to achieve visually:

Related

How to open a new fragment inside the same fragment using viepager and tablayout

I have an application that contains TabLayout with 5 tabs.
Now the need arose to click on an item in the RecycleView to open a new fragment within the Fragment that the user was already using, as if clicking on the item opened the subitems
My problem is that it uses ViewPager(Container)
In the parent Fragment I have the following code
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position){
// MyListModel model = mList.get(holder.getAdapterPosition());
switch(holder.getItemViewType()){
case 1:{
MyViewHolder viewHolder = (MyViewHolder) holder;
viewHolder.Name.setTextColor(Color.parseColor("#245251")); //Todo Muda a cor da linha dos itens do RecycleView 08-08-2022
String nome = telemensagens.get(position).getName();
//String pasta = nome.substring(0,nome.lastIndexOf('-') );
String pasta = nome.lastIndexOf('_')>0 ? nome.substring(0,nome.lastIndexOf('_') ) : nome;
String index = nome.substring(nome.lastIndexOf('_') + 1).trim();
viewHolder.Name.setText(pasta);//telemensagens.get(position).getName());
viewHolder.Email.setText(telemensagens.get(position).getUrl());
final String music = telemensagens.get(position).getUrl();
viewHolder.Name.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment myFragment;
/* Intent intent = new Intent(context, TelemensagensItensActivity.class);
intent.putExtra("PASTA", telemensagens.get(position).getName() );
context.startActivity(intent);*/
Bundle bundle = new Bundle();
String nome = telemensagens.get(position).getName();
if(MainActivity.nivelPasta==0)
MainActivity.nivelPastaFinal = nome.lastIndexOf('_')>0 ? Integer.parseInt(nome.substring(nome.lastIndexOf('_') + 1).trim()) : 1;
//MainActivity.nivelPastaFinal = Integer.parseInt(telemensagens.get(position).getName().substring(telemensagens.get(position).getName().length()-1,telemensagens.get(position).getName().length()));
MainActivity.nivelPasta++;
if(MainActivity.nivelPasta==MainActivity.nivelPastaFinal) {
myFragment = new AudiosItensActivity();
bundle.putString("PASTA",telemensagens.get(position).getName() );
MainActivity.audios.add(telemensagens.get(position).getName());
}
else {
myFragment = new AudiosActivity();
MainActivity.audios.add(telemensagens.get(position).getName());
bundle.putString("PASTA", MainActivity.nomePasta+ telemensagens.get(position).getName() );
MainActivity.nomeAudio += telemensagens.get(position).getName() + "/";
}
AppCompatActivity activity = (AppCompatActivity) context;
myFragment.setArguments(bundle);
activity.getSupportFragmentManager().beginTransaction().replace(R.id.container, myFragment,"Audio").
addToBackStack(null).commit();
}
});
break;
}
case 2:{
break;
}
}
}
In this specific piece of code is the click of the item in the recycleView, when clicking on it I can open a new child fragment, BUT it ends up killing my TabLayout, that is, the tabs stop working and I can no longer navigate in the other tabs
AppCompatActivity activity = (AppCompatActivity) context;
myFragment.setArguments(bundle);
activity.getSupportFragmentManager().beginTransaction().replace(R.id.container, myFragment,"Audio").addToBackStack(null).commit();
So my question is: How can I replace a single fragment and not my entire container with all fragments
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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:fitsSystemWindows="true"
tools:context="com.testapp.EventActivity">
<RelativeLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="100dp">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/adViewMob"
android:layout_weight="1">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
app:tabTextAppearance="#style/MinhaCustomTabText" />
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/adViewMob"
android:layout_marginBottom="2dp"
android:animateLayoutChanges="true"
android:fitsSystemWindows="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/adViewMob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:layout_marginTop="5dp"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/ad_unit_id" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.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/nav_header_main">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="170dp">
<com.dvinfosys.ui.NavigationListView
android:id="#+id/expandable_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:divider="#null"
android:groupIndicator="#null"
android:scrollbars="vertical" />
</ScrollView>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
fragment_container.xml
<FrameLayout
xmlns:ads="http://schemas.android.com/apk/res-auto"
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"
android:layout_above="#id/adViewMob"
tools:context="com.mobileboss.bomdiatardenoite.ContainerFragment"
>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/adViewMob"
android:layout_marginBottom="0dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?actionBarSize"
android:id="#+id/rltLayout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
</RelativeLayout>
</FrameLayout>

Navigation Drawer closing on click event

I am unable to click any of my menu items, I cannot swipe from right to left to close the drawer, although, whenever it is opened and I click on the screen it immediately closes.
I have pretty much tried every answer posted to similar questions here on stack overflow and Github:
public class BottomActivity extends AppCompatActivity
implements GestureOverlayView.OnGesturePerformedListener {
RadioGroup radioGroup;
RadioButton Rd1, Rd2, Rd3, Rd4;
DrawerLayout drawer;
#SuppressLint({"RtlHardcoded", "ClickableViewAccessibility"})
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_bottom );
new GestureOverlayView( this );
Objects.requireNonNull( getSupportActionBar() ).setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM );
getSupportActionBar().setCustomView( R.layout.abs_layout_home );
radioGroup = findViewById( R.id.radioGroup );
Rd1 = findViewById( R.id.radioButton );
Rd2 = findViewById( R.id.radioButton2 );
Rd3 = findViewById( R.id.radioButton3 );
Rd4 = findViewById( R.id.radioButton4 );
radioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (Rd1.isChecked()) {
Intent intent = new Intent( getApplicationContext(), BottomActivity.class );
startActivity( intent );
}
if (Rd2.isChecked()) {
Intent intent1 = new Intent( getApplicationContext(), DashBoard.class );
startActivity( intent1 );
}
if (Rd3.isChecked()) {
Intent intent2 = new Intent( getApplicationContext(), SettingsActivity.class );
startActivity( intent2 );
} else {
if (Rd4.isChecked()) {
Intent intent3 = new Intent( getApplicationContext(), Messages.class );
startActivity( intent3 );
}
}
}
} );
}
#Override
public void onBackPressed() {
if (drawer.isDrawerOpen( GravityCompat.START )) {
drawer.closeDrawer( GravityCompat.START );
} else {
super.onBackPressed();
}
}
public void onDrawerSlide() {
DrawerLayout drawerLayout = findViewById( R.id.DrawerLayout);
drawerLayout.addDrawerListener(
new DrawerLayout.DrawerListener() {
#Override
public void onDrawerSlide(#NonNull View view, float v) {
}
#Override
public void onDrawerOpened(#NonNull View view) {
}
#Override
public void onDrawerClosed(#NonNull View view) {
}
#Override
public void onDrawerStateChanged(int i) {
}
}
);
}
#Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.nav_profile:
startActivity( new Intent(BottomActivity.this, ProfileActivity.class));
return true;
case R.id.nav_settings:
startActivity( new Intent( BottomActivity.this, SettingsActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Here is my navigation drawer XML code:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:openDrawer="start"
tools:openNavigationView="start"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
<include
layout="#layout/app_bar_nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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/nav_header_nav_drawer"
app:menu="#menu/activity_nav_drawer_drawer" />
Here is my activities XML code:
<?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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:elevation="10dp"
android:foregroundGravity="center"
android:gravity="center"
android:orientation="vertical"
tools:context=".BottomActivity"
tools:targetApi="lollipop"
app:layout_collapseMode="parallax">
<include
android:id="#+id/include"
layout="#layout/activity_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorPrimary"
android:gravity="bottom"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/iconColor"
android:checked="true"
android:drawableTop="#drawable/ic_home_black_24dp"
android:padding="10dp"
android:tag="1"
android:text="#string/home"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconColor"
android:drawableTop="#drawable/ic_notifications_black_24dp"
android:padding="10dp"
android:text="#string/notifications"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconColor"
android:drawableTop="#drawable/ic_people_icon"
android:padding="10dp"
android:text="#string/People"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconcolor"
android:drawableTop="#drawable/ic_msg_icon"
android:padding="10dp"
android:text="#string/Messages"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
</RadioGroup>
</android.support.design.widget.CoordinatorLayout>
In BottomActivity add this in your onCreate:
NavigationView nav_view;
nav_view = findViewById(R.id.nav_view); //select nav_view from activity_drawer_layout
nav_view.setNavigationItemSelectedListener(this);
In activity_drawer_layout.xml put the NavigationView above the closing tag for the DrawerLayout.
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DrawerLayout"
android:id="#+id/DrawerLayout">
<include
android:id="#+id/include"
layout="#layout/app_bar_nav_drawer"
android:layout_width="0dp"
android:layout_height="0dp" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="673dp"
android:padding="16dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cv">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/age"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:layout_constraintBottom_toBottomOf="#+id/nav_header" />
<include
android:id="#+id/include"
layout="#layout/app_bar_nav_drawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
app:headerLayout="#layout/nav_header_nav_drawer"
app:menu="#menu/activity_nav_drawer_drawer" />
</android.support.v4.widget.DrawerLayout>

How to add views under collapsing toolbar layout?

I want to add collapsing toolbar in my app. I want to add a graph layout also image view and text views inside the collapsing toolbar layout. Like this image.
This graph is in collapsing toolbar layout. When we do scroll up graph goes up and remains as a toolbar.
Now I am trying to add views under collapsing toolbar layout. But I am not able to move them and align them. How to do?
Layout:
<android.support.design.widget.CoordinatorLayout 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:id="#+id/parentPanel"
xmlns:fab="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="#+id/appbar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_reorder_black_48dp"
android:id="#+id/navigationMenu" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_check_box_white_24dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp">
<include layout="#layout/card_layout" />
<include layout="#layout/card_layout" />
<include layout="#layout/card_layout" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|right|end"
style="#style/FabStyle"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor = "#id/parentPanel"
app:layout_anchorGravity = "bottom|right|end"
android:padding="20dp"
android:weightSum="1">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu1"
android:layout_width="match_parent"
android:layout_height="219dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
fab:menu_backgroundColor="#ccffffff"
fab:menu_fab_label="Menu label"
android:layout_gravity="bottom">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_white_24dp"
fab:fab_size="mini"
fab:fab_label="addList" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list1" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list2" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list3" />
</com.github.clans.fab.FloatingActionMenu>
</LinearLayout>
Activity:
public class MainActivity extends AppCompatActivity {
private CollapsingToolbarLayout collapsingToolbarLayout = null;
private FloatingActionButton fab1;
private FloatingActionButton fab2;
private FloatingActionButton fab3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final FloatingActionMenu menu1 = (FloatingActionMenu) findViewById(R.id.menu1);
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle("List Title");
ImageView navigationMenu = (ImageView)findViewById(R.id.navigationMenu);
fab1 = (FloatingActionButton) findViewById(R.id.fab1);
fab2 = (FloatingActionButton) findViewById(R.id.fab2);
fab3 = (FloatingActionButton) findViewById(R.id.fab3);
fab1.setOnClickListener(clickListener);
fab2.setOnClickListener(clickListener);
fab3.setOnClickListener(clickListener);
navigationMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,NavigationMenuActivity.class));
overridePendingTransition(R.anim.left, R.anim.enter);
}
});
menu1.setOnMenuButtonClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (menu1.isOpened()) {
Toast.makeText(MainActivity.this, menu1.getMenuButtonLabelText(), Toast.LENGTH_SHORT).show();
}
menu1.toggle(true);
}
});
menu1.setClosedOnTouchOutside(true);
dynamicToolbarColor();
toolbarTextAppernce();
}
private void dynamicToolbarColor() {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.b);
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
#Override
public void onGenerated(Palette palette) {
collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimary)));
collapsingToolbarLayout.setStatusBarScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimaryDark)));
}
});
}
private void toolbarTextAppernce() {
collapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.collapsedappbar);
collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.expandedappbar);
}
private View.OnClickListener clickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
String text = "";
switch (v.getId()) {
case R.id.fab1:
text = fab1.getLabelText();
break;
case R.id.fab2:
text = fab2.getLabelText();
fab2.setVisibility(View.GONE);
break;
case R.id.fab3:
text = fab3.getLabelText();
fab2.setVisibility(View.VISIBLE);
break;
}
}
};
}
Now I have a single image view inside collapsing toolbar layout and that I can't move or align. How to align view and add views under collapsing toolbar?
Thank you..
CollapsingToolbarLayout is a subclass of FrameLayout.
For maximum flexibility, put all your widgets inside a LinearLayout or RelativeLayout and make it the only child of the CollapsingToolbarLayout. Also for best results with vertical sizing, set the height to a specific dimension.
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/graph_toolbar_height"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax">
<!-- graph UI here -->
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
Create a layout inside collapsingtoolbarlayout and add your views in there.
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#color/colorPrimary"
app:expandedTitleGravity="bottom|center_horizontal"
app:expandedTitleMarginBottom="64dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="230dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_about"
app:layout_collapseMode="parallax" />
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/colorAccent"
android:text="#string/about_title"
android:textSize="#dimen/text_size_large" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_marginTop="#dimen/status_bar_height"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

Android Set FAB Behavior for ListView

I'm currently developing an application which have a ListView and a FAB. Now what i want to do is hide the FAB on the beginning and then show it after my ListView is scroll down. I have my content_main.xml where the ListView is coded, and activity_main.xml where my FAB is.
activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.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:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_up" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/words_list_view"
android:divider="#00000000"
android:listSelector="#drawable/list_selector"
android:layout_weight="1" />
</RelativeLayout>
and in my Main_Activity.java i have onScrollListener where i'am stock, thinking that this is where i can handle the behavior of FAB.
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
int preLast;
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
final int lastItem = firstVisibleItem + visibleItemCount;
if (lastItem > 20) {
if (preLast != lastItem) {
// SHow FAB Here
}
} else {
// Hide FAB Here
}
}
});
I hope you guys understand my problem. Thank You Very Much! Any Help Would Be Appreciated!

Android Eclipse Start Fragment from TabLayout Tab

I have implemented a TabLayout which has a few tabs & one of the tabs has a table & when a user clicks on a row in the table I need it to get rid of the tab layout, except for the toolbar & open up a new Fragment.
I've tried a few different ways but nothing seems to work, if anyone has any ideas, it'll will be much appreciated!
Thank you!
Cheers!
This is the activity_main.xml
<RelativeLayout
android:id="#+id/main_layout"
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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tab_layout"/>
</RelativeLayout>
& this is the MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("Tab1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab2"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
final PagerAdapter adapter = new PagerAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
& this is tab1.xml
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#F0F0F0" >
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center" >
<TableLayout
android:id="#+id/table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
</TableLayout>
<RelativeLayout
android:id="#+id/loadingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
</FrameLayout>
& this is Tab1.java
public class TopStories extends Fragment {
A lot of code goes here............
public void createTable() {
TableLayout table = (TableLayout) getActivity().findViewById(R.id.table);
table.setBackgroundColor(Color.rgb(240, 240, 240));
table.setStretchAllColumns(true);
table.setShrinkAllColumns(true);
table.removeAllViews();
TableRow row = new TableRow(getActivity());
row .setGravity(Gravity.CENTER);
row .setPadding(0, 10, 0, 10);
row .setBackgroundColor(Color.WHITE);
row .setClickable(true);
TableRow.LayoutParams params = new TableRow.LayoutParams();
row .setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
This is where I need to start up the new fragment (NewFragment.Java).
}
});
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_topstories, container, false);
}
}
NewFragment.java
public class NewFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.newfragment, container, false);
}
}
newfragment.xml
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.04" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="17dp"
android:layout_marginTop="18dp"/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="37dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_marginTop="87dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
I think you need to give the fragment somewhere to replace. Here is the XML from my app, and when I swap fragments, they post to flcontent.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk
xmlns:app="http://schemas.android.com/apk/res
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">
<!-- The ActionBar -->
<include
layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<!-- The main content view -->
<FrameLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
</LinearLayout>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="#+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
app:menu="#menu/drawer_view"
app:headerLayout="#layout/nav_header"/>
and the class code
// Insert the fragment by replacing any existing fragment
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.flContent, fragment);
ft.addToBackStack(null);
ft.commit();
Alright so I think that I figured out a really cheap & a cheeky way to do this & probably not very healthy for the app but it works perfect!
Thank you very much for the help Brian! Appreciate it! Maybe you can do this for the backstack problem of your app as well, don't know if it will work or the right thing that you need to do though.
Cheers!
Added a FrameLayout to my main_activity.xml
<RelativeLayout
android:id="#+id/main_layout"
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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tab_layout"/>
<FrameLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</RelativeLayout>
Changed my newfragment.xml to this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fullStoryLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/fullStoryRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.04" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="17dp"
android:layout_marginTop="80dp"/>
<TextView
android:id="#+id/fullStorytitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/fullStory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/image"
android:layout_marginTop="50dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
& added this to the onClick event of the table row
row.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
getActivity().findViewById(R.id.tab_layout).setVisibility(View.GONE);
getActivity().findViewById(R.id.pager).setVisibility(View.GONE);
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("New Fragment");
Fragment fragment = null;
Class fragmentClass = NewFragment.class;
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.flContent, fragment);
fragmentTransaction.commit();
}
});
& to go back to the main TabLayout from the NewFragment, I added this at MainActivity.java
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch(keyCode){
case KeyEvent.KEYCODE_BACK:
if (getSupportActionBar().getTitle() != "Main Activity"){
onBackPressed();
}
else {
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onBackPressed(){
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle("Main Activity");
findViewById(R.id.fullStoryLinearLayout).setVisibility(View.GONE);
findViewById(R.id.tab_layout).setVisibility(View.VISIBLE);
findViewById(R.id.pager).setVisibility(View.VISIBLE);
}

Categories

Resources