Before starting, I am sorry for the bad English, i'm French.
I have a main activity, which is a navigation bar (ActionBarActivity) whit a DrawerLayout. From this DrawerLayout, I start different Fragment, and one of them has a ViewPager.
I have 3 tab, so 3 Fragment inside. In this 3 Fragment I have a ListView, and when i click on item, an other Fragment take the place of the current Fragment on the tab.
On this new Fragment i have some elements, but the problem become from EditText. The EditText open the keyboard but i can't see what i'm tapping because he is under the keyboard.
I think the problem is the ViewPager, because when I use this Fragment from the navigation menu, I haven't this problem.
I have already try to use ScrollView, and this android:windowSoftInputMode="adjustPan"
There is my ViewPager xml :
<?xml version="1.0" encoding="utf-8"?>
<com.neden.neden.CustomViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vpPager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.PagerTabStrip
android:id="#+id/pager_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#fff"
android:paddingBottom="4dp"
android:paddingTop="4dp" />
</com.neden.neden.CustomViewPager>
After searching in forum, found a solution but now, i havent notification bar.
I use this code in my main activity :
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
If you have an other solution, ...
Related
My App uses a single activity architecture which has a NestedScrollView in the activity layout
<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:id="#+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.navigationadvancedsample.MainActivity">
<androidx.core.widget.NestedScrollView
android:id="#+id/app_scroll_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<FrameLayout
android:id="#+id/nav_host_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</androidx.core.widget.NestedScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/bottom_nav"/>
</LinearLayout>
My issue is that that when I scroll a fragment, then navigate to another, then go back, the scroll position is reset. I've seen another answer which stated that adding IDs to the layouts should fix the issue, but it hasn't for me. Also, interestingly, the scroll position saves fine on configuration change.
I'm using NavigationComponents, could this be related? Here's a sample project that reproduces the issue (based on Google's NavigationAdvancedSample)
NestedScrollView has wrapped the Navigation Container in the activity_main layout. So it is the activity that saves the scroll state. There are 3 fragments. Home fragment has fixed height, Leaderboard and Register fragments are scrolling. When you scroll in the Leaderboard or Register and switch to the other one the scroll state does not change(since both can scroll to roughly the same height) but if you switch to home fragment scroll state resets because it has fixed height(size of the screen). Replacing NestedScrollView with the ScrollView didn't change anything as I examined it.
I think the right design is to wrap each fragment with NestedScrollView and set and get scroll state for each fragment.
Navigation component does not add the fragment to the activity state but replace it. So fragments get recreated after by switching between them. So you see scroll state is being reset. You can check it yourself by putting some log in the onCreateView of first fragment and see the log appears twice.
Can someone provide me with a link where I can read or watch tutorial?
I am using navigation drawer activity and I want to use spinner drop-down-list in second fragment, not fragment which is started when app is launched.
I don't need links for just simple activities.
UPDATED I know how to use spinner, but I don't know how to place it in toolbar. I have just one activity, Main Activity, and 4 fragments, I want to place it only in one fragment to use spinner in toolbar
(image was taken from google, I need same thing)
I hope you will help me to find valid information
For XML
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white">
<Spinner
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#drawable/bac">
</Spinner>
</android.support.v7.widget.Toolbar>
In Activity where you want to hide spinner
spinner.setVisibility(View.GONE);
I'm creating an Android app.
When I click on a menu item, I need to open an activity/view/fragment (I don't know what is the best). This activity/fragment/view need to be placed as an "overlay" of my app (it will have a transparent background and we could see the "regular" activity behind).
I'm using a navigation drawer and a couple of fragment inside my app.
First I tried this :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AlertActivity"
android:id="#+id/alertLayoutRoot"
android:background="#android:color/transparent"
>
<TextView
android:layout_width="match_parent"
android:id="#+id/editText1"
android:text="#string/mes_favoris"
android:layout_height="match_parent"
>
</TextView>
</FrameLayout>
This is indeed showing my fragment, but this fragment isn't on top of all the others.
What could be the best way to do this (in working with Kotlin)?
EDIT : forgot to say, in this view, there will be a small slider.
Basicaly I want this : Overlay
You can use dialog fragment as it supports custom layouts like fragments and shows on top of another activity or fragment.
Here is a useful tutorial on dialog fragment.
I have a layout in my head that should look like that: http://i.imgur.com/H1nTRvd.png
Only part that will be dynamic is the blue one. I don't know the number of tabs that will be created before I load the activity, hence the number is acquired from server (could be either 5 or 24 for all I know).
The bottom buttons should not move when I swipe and the blue area changed.
Currently I have this implemented w/o tabs list using embedded fragment in my activity and gesture listener. There's no good looking transaction animation between fragments.
#Nick Pakhomov: You can use PagerTabStrip
PagerTabStrip
is intended to be used as a child view of a ViewPager widget in your XML layout. PagerTabStrip is most often used with fragment, which is a convenient way to supply and manage the Lifecycle of each fragment.
So here’s how a ViewPager with a PagerTabStrip in it would look like in the layout file:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:id="#+id/pager_tab_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
/>
</android.support.v4.view.ViewPager>
Please check this PagerSlidingTabStrip demo . I hope it will helps you .
I'm using a standard ViewPager inside an Activity. Very basic stuff:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/toolbar" />
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/new_teal"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Now, in my acitivity's code, I have an OnPageChangeListener which I'm using to switch the title in the toolbar whenever the viewpager's views are paged through.
I'm also calling setTitle(...) to set the title for the initial screen.
The issue with all of this is that I'm setting setOffscreenPageLimit(...), and when I do, that initial call to setTitle(...) gets overridden or hidden or something. The title just disappears!!!
If I remove setOffscreenPageLimit(...), then the entire thing misbehaves, as expected.
Any ideas???
For a effective solution we need to see your fragment's code but if you do not set a offScreenPageLimit to a view pager it create 1 previous and one next fragment of your current fragment. All these three fragments gets created and calls default fragment lifecycle methods such as onCreate, onViewCreated and etc.
If you are changing your title in one of your fragments which will be created when you set offScreenPageLimit to 2 or more, you can get this behave.
For example let's say your current Fragment is C and your view pager contains a b C d e and you change title in a or e fragments or other fragments in second or more position.
I hope this'll help you.