android-navigation

Navigation drawer doesn't close

强颜欢笑 提交于 2019-12-03 06:58:47
The navigation drawer in my app is not closing. I am using activities instead of fragments. When i click on any item in the listview , it opens other activities as it should but when i go back, the drawer is still open. I have tried using DrawerLayout.closeDrawers(); but it did not work. How do I close the navigation drawer? Here is my code: Java public class MainActivity extends FragmentActivity { final String[] data ={"Aluminium","Gold","Zinc"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

How to resume activity instead of restart when going “up” from action bar

◇◆丶佛笑我妖孽 提交于 2019-12-03 04:32:44
问题 I have two activities. Say Activity A and Activity B . From Activity A I click a button to launch Activity B This is the code I use for this: Intent intent = new Intent(this, ActivityB.class); this.startActivity(intent); Now at this point, I am in Activity B . On the on create method of Activity B , I enable the up button. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_news); getActionBar()

Android Navigation Architecture Component - Get current visible fragment

[亡魂溺海] 提交于 2019-12-02 21:39:47
Before trying the Navigation component I used to manually do fragment transactions and used the fragment tag in order to fetch the current fragment. val fragment:MyFragment = supportFragmentManager.findFragmentByTag(tag):MyFragment Now in my main activity layout I have something like: <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/nav_host" app:navGraph= "@navigation/nav_item" android:name="androidx.navigation.fragment.NavHostFragment" app:defaultNavHost= "true" /> How can I retrieve the current displayed fragment by the Navigation component

How to resume activity instead of restart when going “up” from action bar

左心房为你撑大大i 提交于 2019-12-02 17:02:21
I have two activities. Say Activity A and Activity B . From Activity A I click a button to launch Activity B This is the code I use for this: Intent intent = new Intent(this, ActivityB.class); this.startActivity(intent); Now at this point, I am in Activity B . On the on create method of Activity B , I enable the up button. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_news); getActionBar().setDisplayHomeAsUpEnabled(true); //Here// } and on the event handle for the "up" button, i have this code: public boolean

How to keep fragment view state?

随声附和 提交于 2019-12-02 16:19:17
问题 I have doubt in fragment system. I have two fragments like A and B If i move A to B , Navigation.findNavController(v).navigate(R.id.B) Now A fragment onDestroyView is called i know it's normal. After in B Fragment i called PopBackStack Navigation.findNavController(v).popBackStack() now A fragment onViewCreated is called i also know it's normal. Now A fragment all ui is initial state. My question is how to keep A fragment UI State like recyclerview scroll position, FAB button visibility, etc

OnClick for navigationDrawer not loading new fragments

北城余情 提交于 2019-12-02 06:54:11
I have been trying to create a navigationDrawer for my project. I have been following this review here: http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/ I have been editing the code a bit, to use my own layout, in order to take out the icons and notifications in the navigation drawer. I just needed a simple one. I have the drawer mostly working except for the onCLicks. I am not getting any errors, but when I click an item in my NavDrawer it does not load the new fragment. I am not getting any error. Here is my code: MainDrawer2: public class MainDrawer2 extends

Android - Clearing Navigation Backstack

亡梦爱人 提交于 2019-12-02 06:04:47
问题 I have 4 pages. From page_1 > page_2 > page_3 > page_4. Once the user reaches page_3 and clicks a button, it navigates to page_4. Once the button is clicked, I want to clear all the navigation history so when the user goes back on page_4, the app quits rather than going back to page_3. I've tried: Intent intent = new Intent(this, page_4.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); But nothing happens. I can still go

Android - Clearing Navigation Backstack

谁说胖子不能爱 提交于 2019-12-02 00:31:21
I have 4 pages. From page_1 > page_2 > page_3 > page_4. Once the user reaches page_3 and clicks a button, it navigates to page_4. Once the button is clicked, I want to clear all the navigation history so when the user goes back on page_4, the app quits rather than going back to page_3. I've tried: Intent intent = new Intent(this, page_4.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); But nothing happens. I can still go back to page_3, page_2 etc. How do I make it so that when the user clicks on the button on page_3, he

Why does findViewById(R.android.id.home) always return null?

随声附和 提交于 2019-12-01 23:22:08
问题 I'm using AppCompat and trying to recall the ImageView for the up/back button belonging to the toolbar. I know R.android.id.home exists, because I can manage its click as a Menu item: public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { //this works } return super.onOptionsItemSelected(item); } Apart from that, whenever I try to call findViewById(android.R.id.home) - be it onCreate , be it onClick of a custom button - I get null. I even get null

Why does findViewById(R.android.id.home) always return null?

纵然是瞬间 提交于 2019-12-01 22:36:28
I'm using AppCompat and trying to recall the ImageView for the up/back button belonging to the toolbar. I know R.android.id.home exists, because I can manage its click as a Menu item: public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { //this works } return super.onOptionsItemSelected(item); } Apart from that, whenever I try to call findViewById(android.R.id.home) - be it onCreate , be it onClick of a custom button - I get null. I even get null if, in the sample above, I call findViewById(item.getItemId()) . Why is it? This question has been asked