I use BottomNavigationBar(bnb) with Navigation(android jetpack). It's a single-activity app. There are 3 fragments. One of them is starting. When I perform the navigation from starting fragment to any outher, bnb goes down for half of it hight. When I go back or perform navigation between not starting fragments everything is ok.
Activity
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
tools:context=".ui.activities.MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemIconSize="#dimen/bnb_icon_size"
android:background="?attr/colorPrimary"
app:itemIconTint="#drawable/selector"
app:elevation="#dimen/margin_small"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/bottom_navigation_menu" />
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constrainedWidth="true"
app:layout_constrainedHeight="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/bottom_navigation_view"
app:defaultNavHost="true"
app:navGraph="#navigation/nav_graph"/>
</androidx.constraintlayout.widget.ConstraintLayout>
one of the fragments
<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">
<data>
<variable
name="callback"
type="(...)ui.info.InfoFragmentCallback" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/set_coord_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:fitsSystemWindows="true">
<TextView
android:id="#+id/info_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_email"
android:textColor="#color/colorWhiteOverlayTransparency45"
android:textSize="#dimen/text_size_small"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/info_contact_us_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_medium"
android:gravity="center"
android:text="#string/title_contact_us"
android:textColor="#color/colorWhiteOverlayTransparency45"
android:textSize="#dimen/text_size_medium"
android:textStyle="italic"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="#+id/info_email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/info_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_large"
android:gravity="center"
android:text="#string/app_version"
android:textColor="#color/colorWhiteOverlayTransparency45"
android:textSize="#dimen/text_size_medium"
android:textStyle="italic"
app:layout_constraintBottom_toTopOf="#+id/info_email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/info_app_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_medium"
android:gravity="center"
android:text="#string/title_rate_app"
android:textColor="#color/colorWhiteOverlayTransparency45"
android:textSize="#dimen/text_size_medium"
android:textStyle="italic"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="#+id/info_google_badge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/info_google_badge"
android:layout_width="wrap_content"
android:layout_height="#dimen/icon_size_large"
android:elevation="#dimen/margin_medium"
android:onClick="#{(view)->callback.onAppRateClicked()}"
android:src="#drawable/google_play_badge"
app:layout_constraintBottom_toTopOf="#+id/info_privacy_policy"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/info_email"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/info_privacy_policy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_huge"
android:onClick="#{(view)->callback.onPrivacyClicked()}"
android:text="#string/privacy_policy_title"
android:textColor="#color/colorSecondary"
android:textSize="#dimen/text_size_small"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
MainActivity
public class MainActivity extends AppCompatActivity {
private BottomNavigationView bottomNavigationView;
private NavController mNavController;
private final BottomNavigationView.OnNavigationItemReselectedListener mOnNavigationItemReselectedListener = item -> {
/*multiple touches may must nothing*/
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavController = Navigation.findNavController(this, R.id.nav_host_fragment);
bottomNavigationView = findViewById(R.id.bottom_navigation_view);
NavigationUI.setupWithNavController(bottomNavigationView, mNavController);
initBottomNavigationMenu();
}
private void initBottomNavigationMenu() {
bottomNavigationView.setOnNavigationItemReselectedListener(mOnNavigationItemReselectedListener);
}
public void performNavigation(int navId) {
mNavController.navigate(navId);
}
#Override
protected void onDestroy() {
super.onDestroy();
bottomNavigationView.setOnNavigationItemReselectedListener(null);
}
}
bnb menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/starting_fragment"
android:icon="#drawable/ic_image"
android:title=""
app:showAsAction="ifRoom" />
<item
android:id="#+id/favorites_fragment"
android:icon="#drawable/ic_star"
android:title=""
app:showAsAction="ifRoom"/>
<item
android:id="#+id/info_fragment"
android:icon="#drawable/ic_info"
android:title=""
app:showAsAction="ifRoom"/>
</menu>
Where can be a problem?
Related
I'm getting this error on Android 5x but i don't know what it could be the problem. I'm getting the error on the file FragmentDataNewjourneyBindingImpl. So i tracked and the file that is using the FragmentDataNewJourneyBinding is AuthenticationFragment. So it could be either my xml has something wrong or my fragment has.
This is my xml:
<?xml version="1.0" encoding="utf-8"?>
<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">
<data>
<variable
name="viewModel"
type="br.com.gabriel.novajornada.security.auth.AuthenticationViewModel" />
<variable
name="constantes"
type="br.com.gabriel.novajornada.constants.ConstantsKt" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/include"
android:fitsSystemWindows="true">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout11"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
style="#style/bo_texto_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin"
android:layout_marginEnd="#dimen/margin"
android:gravity="center_horizontal"
android:lineSpacingExtra="4sp"
android:text="#string/fill_data_title_new_journey"
android:textColor="#1a1b1a"
android:textSize="24sp"
app:layout_constraintTop_toTopOf="#id/constraintLayout11" />
<TextView
android:id="#+id/textView98"
style="#style/bo_texto_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin"
android:layout_marginTop="#dimen/margin_small"
android:layout_marginEnd="#dimen/margin"
android:gravity="center_horizontal"
android:lineSpacingExtra="6sp"
android:text="#string/fill_data_subtitle"
android:textColor="#4a4b4a"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="#id/textView"
tools:layout_editor_absoluteX="0dp" />
<br.com.original.common.components.BOTextInputLayout
android:id="#+id/text_input_cpf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin"
android:layout_marginTop="19dp"
android:layout_marginRight="#dimen/margin"
android:hint="#string/identifier_field_title"
android:theme="#style/TextInputLayoutTheme.ClearButton"
app:errorEnabled="true"
app:errorTextAppearance="#style/MyProfile.Error"
app:hintTextAppearance="#style/TextLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView98">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/identifier"
style="#style/TextInputEditTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="#={viewModel.credentials.cpf}"
app:mask="#{ `###.###.###-##` }" />
</br.com.original.common.components.BOTextInputLayout>
<br.com.original.common.components.BOTextInputLayout
android:id="#+id/text_input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin"
android:layout_marginRight="#dimen/margin"
android:hint="#string/name_field"
android:inputType="textNoSuggestions|textVisiblePassword"
android:theme="#style/TextInputLayoutTheme.ClearButton"
app:errorEnabled="true"
app:errorTextAppearance="#style/MyProfile.Error"
app:hintTextAppearance="#style/TextLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_input_cpf">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/name"
style="#style/TextInputEditTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ âãàáäêèéëîìíïôòóõöùúüñçÂÃÀÁÄÊÈÉËÎÌÍÏÔÒÓÕÖÙÚÜÑÇ"
android:inputType="textNoSuggestions|textVisiblePassword"
android:maxLength="#{constantes.NAMES_MAX_LENGTH}"
android:text="#={viewModel.credentials.name}" />
</br.com.original.common.components.BOTextInputLayout>
<br.com.original.common.components.BOTextInputLayout
android:id="#+id/text_input_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin"
android:layout_marginRight="#dimen/margin"
android:clipChildren="false"
android:hint="#string/cellphone_ddd_field_title"
android:theme="#style/TextInputLayoutTheme.ClearButton"
app:errorTextAppearance="#style/MyProfile.Error"
app:hintTextAppearance="#style/TextLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_input_name">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/phone"
style="#style/TextInputEditTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="#={viewModel.credentials.phoneNumber}"
app:mask="#{ `(##) #####-####` }" />
</br.com.original.common.components.BOTextInputLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="#dimen/margin"
app:layout_constraintBottom_toTopOf="#+id/btnConfirm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_input_phone"
app:layout_constraintVertical_bias="1.0">
<TextView
android:id="#+id/politicas"
style="#style/seja_subtitle_h3_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingStart="#dimen/margin"
android:paddingEnd="#dimen/margin"
android:text="#string/politicas_header_new_journey"
android:textSize="#dimen/text_small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteY="4dp" />
<TextView
android:id="#+id/openPoliticas"
style="#style/seja_subtitle_h3_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingStart="#dimen/margin"
android:paddingTop="2pt"
android:paddingEnd="#dimen/margin"
android:text="#string/privacy_policy_new_journey"
android:textSize="#dimen/text_small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/politicas" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="#+id/btnConfirm"
style="#style/seja_button_bordeless"
android:layout_width="match_parent"
android:layout_height="#dimen/button_height_seja"
android:layout_marginStart="#dimen/margin"
android:layout_marginTop="#dimen/margin"
android:layout_marginEnd="#dimen/margin"
android:enabled="#{identifier.text.length() == 14 && phone.text.length() == 15 && name.text.length() > 2}"
android:text="#string/continue_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<include
android:id="#+id/include"
layout="#layout/seja_bar_layout_newjourney_center" />
<br.com.original.bank.novajornada.common.component.BOStateView
android:id="#+id/stateView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:msv_errorView="#layout/seja_error_view_newjourney"
app:msv_loadingView="#layout/seja_loading_view_newjourney" />
</RelativeLayout>
</layout>
This is AuthenticationFragment.kt. I put only the part of the bindingView declaration because i think it's more important:
#ExperimentalCoroutinesApi
class AuthenticationFragment : NavigationFragment() {
val viewModel: AuthenticationViewModel by viewModel()
lateinit var bindingView: FragmentDataNewjourneyBinding
lateinit var formValidate: FormValidate
private val novaJornadaActivity: NovaJornadaActivity by lazy { activity as NovaJornadaActivity }
private val management: TagManagement by inject()
#ExperimentalCoroutinesApi
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
bindingView = DataBindingUtil.inflate<FragmentDataNewjourneyBinding>(inflater, R.layout.fragment_data_newjourney, container, false)
.apply {
lifecycleOwner = this#AuthenticationFragment
viewModel = this#AuthenticationFragment.viewModel
}
viewModel.checkUserPromoted((activity as NovaJornadaActivity).userPromoted)
return bindingView.root
}
Is there something wrong with my implementation? I will be glad for anyone for trying to help me
I make an application android for a school project , and actually i have a problem.
I have create 2 activity (MainActivity and BottomNavActivity), and I try to navigate between them, but the "fragment" home page in my navigation Remain undefined.
I found this tutorial in order to navigate between the fragments
and I added events) :
https://medium.com/#oluwabukunmi.aluko/bottom-navigation-view-with-fragments-a074bfd08711
But, now, I can navigate between my "fragments" BUT my initial "fragment" (the one that appears first when launching the activity), remains, and therefore when changing fragments, it is duplicated.
Here is a video of my problem
My Infos.class
public class Infos extends AppCompatActivity {
private ActivityInfosBinding binding;
//I create my variable
final Fragment frag2 = new ProduitsFragment();
final Fragment frag1 = new EntrepriseFragment();
final Fragment frag3 = new CGUFragment();
final FragmentManager fm = getSupportFragmentManager();
Fragment active = frag1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityInfosBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_entreprise, R.id.navigation_produits, R.id.navigation_CGU)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_infos);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(binding.navView, navController);
//I add my differents fragments
fm.beginTransaction().add(R.id.nav_host_fragment_activity_infos, frag3).hide(frag3).commit();
fm.beginTransaction().add(R.id.nav_host_fragment_activity_infos,frag1).hide(frag1).commit();
navView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull #NotNull MenuItem item) {
switch (item.getItemId()) {
//My first fragment
case R.id.navigation_entreprise:
fm.beginTransaction().hide(active).show(frag1).commit();
active = frag1;
return true;
//My second fragment (default in video)
case R.id.navigation_CGU:
fm.beginTransaction().hide(active).show(frag3).commit();
active = frag3;
return true;
}
return false;
}
});
}
}
And my mobile_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
app:startDestination="#id/navigation_CGU"> //I try to change this, but nothing. This fragment is duplicated.
<fragment
android:id="#+id/navigation_entreprise"
android:name="fr.romaindrouhot.aurelinfo.ui.home.EntrepriseFragment"
android:label="#string/nav_entreprise"
tools:layout="#layout/fragment_entreprise" />
<fragment
android:id="#+id/navigation_produits"
android:name="fr.romaindrouhot.aurelinfo.ui.home.ProduitsFragment"
android:label="#string/nav_produits"
tools:layout="#layout/fragment_produits" />
<fragment
android:id="#+id/navigation_CGU"
android:name="fr.romaindrouhot.aurelinfo.ui.home.CGUFragment"
android:label="#string/nav_CGU"
tools:layout="#layout/fragment_cgu" />
</navigation>
Can you help me ?
yes, here is my activity_infos.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
<fragment
android:id="#+id/nav_host_fragment_activity_infos"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultNavHost="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:navGraph="#navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
My fragment_cgu.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textSize="50sp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
My fragment_entreprise.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"
tools:context=".ui.home.EntrepriseFragment"
android:id="#+id/fragment_entreprise"
android:background="#drawable/logonoiretblanc">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/entreprise_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:textColor="#color/black"
android:textSize="#dimen/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/border"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/entreprise_title"
android:layout_marginTop="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/informations"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="#+id/linearLayout"
app:layout_constraintTop_toTopOf="#+id/linearLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</LinearLayout>
<TextView
android:id="#+id/title_gerant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gerant_title"
android:shadowColor="#color/black"
android:shadowRadius="1"
android:textAlignment="center"
android:textColor="#color/dark_green"
android:textSize="#dimen/gerant_title"
app:layout_constraintTop_toBottomOf="#+id/linearLayout"
android:layout_marginTop="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/gerant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gerant"
android:textAlignment="center"
android:textColor="#color/blue"
android:textSize="#dimen/gerant"
app:layout_constraintTop_toBottomOf="#+id/title_gerant"
android:layout_marginTop="#dimen/espace_entre_title_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/title_localisation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/localisation_title"
android:textAlignment="center"
android:textColor="#color/dark_green"
android:shadowColor="#color/black"
android:shadowRadius="1"
android:textSize="#dimen/gerant_title"
app:layout_constraintTop_toBottomOf="#+id/gerant"
android:layout_marginTop="#dimen/espace_entre_text_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/localisation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/localisation"
android:textAlignment="center"
android:textColor="#color/blue"
android:textSize="#dimen/gerant"
app:layout_constraintTop_toBottomOf="#+id/title_contact"
android:layout_marginTop="#dimen/espace_entre_title_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/title_activite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_activite"
android:textAlignment="center"
android:textColor="#color/dark_green"
android:shadowColor="#color/black"
android:shadowRadius="1"
android:textSize="#dimen/gerant_title"
app:layout_constraintTop_toBottomOf="#+id/localisation"
android:layout_marginTop="#dimen/espace_entre_text_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/activite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/activite"
android:textAlignment="center"
android:textColor="#color/blue"
android:textSize="#dimen/gerant"
app:layout_constraintTop_toBottomOf="#+id/title_activite"
android:layout_marginTop="#dimen/espace_entre_title_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/title_contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_contact"
android:textAlignment="center"
android:textColor="#color/dark_green"
android:shadowColor="#color/black"
android:shadowRadius="1"
android:textSize="#dimen/gerant_title"
android:layout_marginTop="#dimen/espace_entre_text_title"
app:layout_constraintTop_toBottomOf="#+id/activite"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="#+id/contact_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/contact"
android:textAlignment="center"
android:textColor="#color/blue"
android:textSize="#dimen/gerant"
app:layout_constraintTop_toBottomOf="#+id/title_contact"
android:layout_marginTop="#dimen/espace_entre_title_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</LinearLayout>
</ScrollView>
</LinearLayout>
As I mentioned in the comment section, the Navigation Component deals itself with the transactions between the fragments.
Here some tips to set up your BottomNavigation bar, hope it will help you.
First of all your mobile_navigation.xml and fragment XML seems to be good.
I could fix a bit your activity_infos.xml file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/nav_host_fragment_activity_infos"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="Odp"
app:defaultNavHost="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#id/nav_view"
app:navGraph="#navigation/mobile_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
...
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
...
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Update your Left/Right constraint with Start/End here is why
Add a constraint between the bottom of the id/nav_host_fragment_activity_infos and the id/nav_view, just to be sure the fragment never be hidden by the navbar. It is optional.
Then, your activity could be updated without the FrragmentManager:
public class Infos extends AppCompatActivity {
private ActivityInfosBinding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// When you are using an activity you can directly use this
binding = DataBindingUtil.setContentView(this, R.layout.activity_infos);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top-level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_entreprise, R.id.navigation_produits, R.id.navigation_CGU)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_infos);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(binding.navView, navController);
}
}
I found this tutorial, it explains step by step, and it may provide more info than my "tips".
Can you please try replacing this with your activity_infos.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
<fragment
android:id="#+id/nav_host_fragment_activity_infos"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultNavHost="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:navGraph="#navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have the following XML
<?xml version="1.0" encoding="utf-8"?>
<layout>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fragment_inspection_details_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="#dimen/size_0dp"
android:layout_height="#dimen/size_0dp"
app:layout_constraintBottom_toTopOf="#+id/fragment_inspection_details_buttons_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/fragment_inspection_details_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/details"
android:textAllCaps="true"
android:textColor="#color/gold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="#dimen/size_0dp"
android:layout_height="1dp"
android:layout_margin="#dimen/size_16dp"
android:background="#color/lightGray"
app:layout_constraintBottom_toBottomOf="#+id/fragment_inspection_details_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fragment_inspection_details_title"
app:layout_constraintTop_toTopOf="#+id/fragment_inspection_details_title" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_status_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_title">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_status_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/status" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_start_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_status_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_start_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/start_time" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_end_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_start_time_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_end_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/end_time" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_desc_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_end_time_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_desc_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/description" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/fragment_inspection_details_handling_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/handling"
android:textAllCaps="true"
android:textColor="#color/gold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_desc_time_til" />
<View
android:layout_width="#dimen/size_0dp"
android:layout_height="1dp"
android:layout_margin="#dimen/size_16dp"
android:background="#color/lightGray"
app:layout_constraintBottom_toBottomOf="#+id/fragment_inspection_details_handling_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fragment_inspection_details_handling_title"
app:layout_constraintTop_toTopOf="#+id/fragment_inspection_details_handling_title" />
<TextView
android:id="#+id/fragment_inspection_details_outcome_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/outcome"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_handling_title" />
<Spinner
android:id="#+id/fragment_inspection_details_outcome_spinner"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/size_8dp"
android:layout_marginEnd="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_outcome_title" />
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/size_16dp"
android:layout_marginEnd="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_outcome_spinner">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_outcome_report_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Outcome report" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<LinearLayout
android:id="#+id/fragment_inspection_details_buttons_container"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatButton
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:layout_weight="1"
android:background="#drawable/white_background_gray_rounded_border"
android:text="#string/save"
android:textAllCaps="false" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:layout_weight="1"
android:background="#drawable/white_background_gray_rounded_border"
android:text="#string/handle"
android:textAllCaps="false" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
and the following code -
class InspectionDetailsFragment : Fragment() {
companion object {
fun newInstance(inspection: Inspection): InspectionDetailsFragment {
val inspectionDetailsFragment = InspectionDetailsFragment()
val bundle = Bundle()
bundle.putParcelable(Constants.INSPECTION, inspection)
inspectionDetailsFragment.arguments = bundle
return inspectionDetailsFragment
}
}
...
...
}
//Inside another Fragment
changeFragment(
parentFragmentManager, R.id.fragment_inspection_details_root,
InspectionDetailsFragment.newInstance(inspection), true
)
// Change fragment extension function to handle navigation easily
#SuppressLint("PrivateResource")
fun changeFragment(fragmentManager: FragmentManager?, #IdRes containerId: Int, fragment: Fragment?, addToBackStack: Boolean = false) {
if (fragmentManager == null) return
val fragmentTransaction = fragmentManager.beginTransaction()
if (addToBackStack) fragmentTransaction.addToBackStack(null)
/*fragmentTransaction.setCustomAnimations(
R.anim.abc_fade_in,
R.anim.abc_shrink_fade_out_from_bottom,
R.anim.abc_grow_fade_in_from_bottom,
R.anim.abc_popup_exit
)*/
fragment?.let {
fragmentTransaction
.replace(containerId, it, it::class.java.simpleName)
.commit()
}
}
For some reason when trying to navigate to the InspectionDetailsFragment the app crashes with the No view found for id 0x7f0900df (com.supercom.myapplication:id/fragment_inspection_details_root) for fragment InspectionDetailsFragment I really have no idea what's wrong, I tried to look up but it seems like I am doing everything correct.
The InspectionDetailsFragment used to have a container fragment for it but I deleted it, maybe that is related to the issue I am getting?
In Fragment, I made initUI() and initializes image view, but getting error.Not able why it is getting an error. I'm providing Fragment's initUI() and XML files.
Error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at novumlogic.payment.home.CateFragment.initUI(CateFragment.java:95)
at novumlogic.payment.home.CateFragment.onCreate(CateFragment.java:61)
Fragment
private void initUI() {
//#SuppressLint("ResourceType") AppCompatTextView tvDay = ((AppCompatTextView) rootView.findViewById(R.id.imgSendMoney,16.0F));
//AppCompatTextView tvDay1 = (AppCompatTextView) rootView.findViewById(R.id.imgReceiveMoney);
ViewCompat.setElevation((ImageView) rootView.findViewById(R.id.imgSendMoney), 16.0F);
ViewCompat.setElevation((ImageView)rootView.findViewById(R.id.imgReceiveMoney), 16.0F);
/*((AppCompatImageView)root.findViewById(R.id.imgNotification)).setOnClickListener((View.OnClickListener) new View.OnClickListener() {
public final void onClick(View it) {
Toast.makeText((Context)HomeFragment.this, (CharSequence)"Notification List", 0).show();
}
});*/
((CardView)rootView.findViewById(R.id.cardSendMoney)).setOnClickListener((View.OnClickListener)(new View.OnClickListener() {
public final void onClick(View it) {
Intent k = new Intent(getContext(), SendMoneyActivity.class);
startActivity(k);
//HomeFragment.this.startActivity(new Intent((Context)HomeFragment.this.getActivity(), SendMoneyActivity.class));
}
}));
CardView card_view = (CardView) rootView.findViewById(R.id.cardReceiveMoney);
card_view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// do whatever you want to do on click (to launch any fragment or activity you need to put intent here.)
Intent k = new Intent(getContext(), ReceiveMoneyActivity.class);
startActivity(k);
}
});
((RecyclerView)rootView.findViewById(R.id.recyclerBankAccounts)).setItemViewCacheSize(0);
((RecyclerView)rootView.findViewById(R.id.recyclerBankAccounts)).setHasFixedSize(true);
RecyclerView var10000 = (RecyclerView)rootView.findViewById(R.id.recyclerBankAccounts);
Intrinsics.checkExpressionValueIsNotNull(var10000, "root.recyclerBankAccounts");
var10000.setLayoutManager((RecyclerView.LayoutManager)(new LinearLayoutManager((Context)this.getActivity(), 0, false)));
BankAccountsListAdapter bankAccountsAdapter = new BankAccountsListAdapter();
var10000 = (RecyclerView)rootView.findViewById(R.id.recyclerBankAccounts);
Intrinsics.checkExpressionValueIsNotNull(var10000, "root.recyclerBankAccounts");
var10000.setAdapter((RecyclerView.Adapter)bankAccountsAdapter);
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgLogo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="#dimen/margin_8"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginBottom="#dimen/margin_16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/fee_logo" />
<android.support.v7.widget.AppCompatTextView
style="#style/BoldTitleStyle"
android:layout_margin="#dimen/margin_8"
android:text="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/imgLogo"
app:layout_constraintStart_toEndOf="#id/imgLogo"
app:layout_constraintTop_toTopOf="#+id/imgLogo" />
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginEnd="#dimen/margin_8"
android:layout_marginBottom="#dimen/margin_16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_bell_icon" />
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="#id/imgNotification"
app:layout_constraintTop_toTopOf="#id/imgNotification"
app:srcCompat="#drawable/badge" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txtBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/margin_8"
android:text="02"
android:textColor="#color/colorPrimary"
android:textSize="#dimen/text_tiny_8"
app:layout_constraintBottom_toBottomOf="#id/imgBadge"
app:layout_constraintEnd_toEndOf="#id/imgBadge"
app:layout_constraintStart_toStartOf="#id/imgBadge"
app:layout_constraintTop_toTopOf="#id/imgBadge" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="#dimen/margin_8"
android:layout_marginBottom="#dimen/margin_8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/appbar">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txtMyBankAccounts"
style="#style/BoldSubTitleStyle"
android:text="#string/title_my_bank_accounts"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerBankAccounts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="#+id/cardReceiveMoney"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/txtMyBankAccounts" />
<android.support.v7.widget.CardView
android:id="#+id/cardSendMoney"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_8"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginRight="#dimen/margin_4"
android:layout_marginBottom="#dimen/margin_16"
app:cardCornerRadius="#dimen/margin_16"
app:layout_constraintEnd_toStartOf="#+id/cardReceiveMoney"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/recyclerBankAccounts">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="#dimen/margin_8">
<ImageView
android:id="#+id/imgSendMoney"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_8"
android:layout_marginEnd="#dimen/margin_8"
android:background="#drawable/send_money_icon"
android:padding="#dimen/margin_8"
app:srcCompat="#drawable/ic_arrow_forward" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/poppins_bold"
android:padding="#dimen/margin_8"
android:text="#string/msg_send_money"
android:textColor="#color/colorSecondary" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardReceiveMoney"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_4"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginRight="#dimen/margin_8"
android:layout_marginBottom="#dimen/margin_16"
app:cardCornerRadius="#dimen/margin_16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/cardSendMoney"
app:layout_constraintTop_toBottomOf="#id/recyclerBankAccounts">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="#dimen/margin_8">
<ImageView
android:id="#+id/imgReceiveMoney"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_8"
android:layout_marginEnd="#dimen/margin_8"
android:background="#drawable/receive_money_icon"
android:padding="#dimen/margin_8"
app:srcCompat="#drawable/ic_arrow_back" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/poppins_bold"
android:padding="#dimen/margin_8"
android:text="#string/msg_receive_money"
android:textColor="#color/colorSecondary" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txtSendMoneyTo"
style="#style/BoldSubTitleStyle"
android:layout_marginTop="#dimen/margin_22"
android:text="#string/label_send_money_to"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/cardSendMoney" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txtSendMoneyToViewAll"
style="#style/BoldSubTitleStyle"
android:layout_margin="#dimen/margin_8"
android:fontFamily="#font/poppins_medium"
android:text="#string/label_view_all"
android:textSize="#dimen/text_small_14"
app:layout_constraintBaseline_toBaselineOf="#+id/txtSendMoneyTo"
app:layout_constraintEnd_toEndOf="#id/cardReceiveMoney" />
<android.support.v7.widget.CardView
android:id="#+id/linearSendMoneyTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:cardCornerRadius="#dimen/margin_16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/txtSendMoneyTo">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<novumlogic.payment.customview.DashboardContactItem
android:id="#+id/imgAddContact"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:contactImage="#drawable/ic_add_circle"
app:contactName="Add New"
app:hasBackgroundRing="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/contactItem1"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<novumlogic.payment.customview.DashboardContactItem
android:id="#+id/contactItem1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:contactImage="#drawable/ic_avatar"
app:contactName="Alice"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/contactItem2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/imgAddContact"
app:layout_constraintTop_toTopOf="parent" />
<novumlogic.payment.customview.DashboardContactItem
android:id="#+id/contactItem2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:contactImage="#drawable/ic_avatar"
app:contactName="Bob"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/contactItem3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/contactItem1"
app:layout_constraintTop_toTopOf="parent" />
<novumlogic.payment.customview.DashboardContactItem
android:id="#+id/contactItem3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:contactImage="#drawable/ic_avatar"
app:contactName="Emily"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imgViewMore"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/contactItem2"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgViewMore"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/contactItem3"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_keyboard_arrow_right" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/collaps"
android:fitsSystemWindows="true"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
>
<FrameLayout
android:id="#+id/institutions_tab_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.cooltechworks.views.shimmer.ShimmerRecyclerView
android:id="#+id/recycler_view_institutions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/noDataFound"
android:visibility="invisible"
>
<include
layout="#layout/no_data_found"
>
</include>
</LinearLayout>
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Your rootView is null.
Looking at the stacktrace, you're calling initUI() in onCreate(). It is too early. If your rootView is the usual view as inflated in onCreateView(), you need to call initUI() in onCreateView() after inflation, or onViewCreated(), and actually init rootView before that.
I just learn about Shared Element in Android and I have one image which one of them in ActivitySplashScreen and one other is into Toolbar and I want to use shared element to move this image from ActivitySplashScreen to ActivityMain
after some search and try to implement that simple way to make this feature don't work on my code, for example:
style.xml:
<style name="AppTheme" parent="BaseTheme">
<item name="android:windowContentTransitions">true</item>
</style>
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
...
</style>
ActivitySplashScreen.java:
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
ButterKnife.bind(this);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(ActivitySplashScreen.this, MainActivity.class);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(ActivitySplashScreen.this,
app_logo,
ViewCompat.getTransitionName(app_logo));
startActivity(intent, options.toBundle());
finish();
}
}, 3000);
}
ActivityMain.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
supportPostponeEnterTransition();
}
and ImageView widget on my ActivitySplashScreen and ActivityMain xml layout:
<ImageView
android:id="#+id/instagram_add_story"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:src="#drawable/img_wizard_1"
android:transitionName="app_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="VectorDrawableCompat" />
this code is not working as well and I'm not sure what exactly problem on that
UPDATED
ActivitySplashScreen xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<LinearLayout
android:id="#+id/alachiq_header_animation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#drawable/instagram_animation_gradient_list"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="40dp">
<ImageView
android:id="#+id/app_logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:transitionName="app_logo"
android:tint="#android:color/white"
app:srcCompat="#drawable/img_wizard_1" />
<TextView
android:id="#+id/title"
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:fontFamily="#font/iran_sans_bold"
android:gravity="center"
android:text="#string/app_name"
android:textColor="#color/mdtp_white" />
<TextView
style="#style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/iran_sans_light"
android:gravity="center"
android:textColor="#color/mdtp_white" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity 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:slidingLayer="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_5"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="5dp"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/Toolbar.Light">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/activityTitle"
style="#style/Base.TextAppearance.AppCompat.Caption"
android:layout_width="90dp"
android:layout_height="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:fontFamily="#font/iran_sans_bold"
android:gravity="center|right"
android:text="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/application_logo"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/application_logo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:scaleType="centerCrop"
android:layout_marginBottom="8dp"
android:src="#drawable/ic_app_logo"
android:transitionName="app_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/drawerMenu"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="VectorDrawableCompat" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
I can use in this way here is my solution according to your scenario.
Style:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
Splash.XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<LinearLayout
android:id="#+id/alachiq_header_animation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#drawable/ic_launcher_background"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="40dp">
<ImageView
android:id="#+id/app_logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:tint="#android:color/black"
app:srcCompat="#android:drawable/ic_dialog_email" />
<TextView
android:id="#+id/title"
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="#string/app_name"
android:textColor="#android:color/background_dark" />
<TextView
style="#style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:fontFamily="sans-serif"
android:textColor="#android:color/background_dark" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Splash.Java
public class SplashActivity extends AppCompatActivity {
#BindView(R.id.app_logo)
ImageView app_logo;
Activity mActivity;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ButterKnife.bind(this);
mActivity = this;
ViewCompat.setTransitionName(app_logo, "app_logo");
new Handler().postDelayed(new Runnable() {
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
#Override
public void run() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
intent.putExtra("transition_name", ViewCompat.getTransitionName(app_logo));
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(mActivity,app_logo,ViewCompat.getTransitionName(app_logo));
startActivity(intent, options.toBundle());
finish();
}
}, 3000);
}
}
MainActivity.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:slidingLayer="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="5dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:contentInsetStartWithNavigation="0dp"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/activityTitle"
android:layout_width="90dp"
android:layout_height="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center|right"
android:text="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/application_logo"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="8dp" />
<ImageView
android:id="#+id/application_logo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:scaleType="centerCrop"
android:layout_marginBottom="8dp"
android:tint="#android:color/black"
app:srcCompat="#android:drawable/ic_dialog_email"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:layout_marginRight="8dp" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
MainActivity.Java
public class MainActivity extends AppCompatActivity {
#BindView(R.id.toolbar)
Toolbar mToolbar;
Activity mActivity;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mActivity = this;
setSupportActionBar(mToolbar);
ActivityCompat.postponeEnterTransition(this);
ImageView application_logo = (ImageView) mToolbar.findViewById(R.id.application_logo);
if (getIntent() != null) {
Bundle extras = getIntent().getExtras();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
String imageTransitionName = extras.getString("transition_name");
application_logo.setTransitionName(imageTransitionName);
ActivityCompat.startPostponedEnterTransition(mActivity);
}
}
}
}
Here is the Sample code for SharedElementTransition according to your scenario. Whenever you use some kind of style always write in style file then use it.
Note: import android.support.v7.widget.Toolbar; for ToolBar in Java file. This is working fine.