I have a simple single Activity app, the activity has only a toolbar and a FragmentContainerView that acts as the NaHost.
In one of my main screens, I have a Fragment that contains a BottomNavigationView that should toggle between 3 child Fragments. This parent fragment has also a FragmentContainerView that is also defined as a NavHost for the child fragments.
Can this setup work by just using one NavGraph? How can I tell the the navigation component which NavHost to use when switching between main screens which is different to when clicking on the BottomNavigationView items?
Activity 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/app_bar_container"
layout="#layout/app_bar" />
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:defaultNavHost="true"
app:navGraph="#navigation/nav_graph" />
</LinearLayout>
Parent Fragment:
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/tab_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/tab_navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_navigation_items" />
</androidx.constraintlayout.widget.ConstraintLayout>
Related
I have one activity containing 2 fragments as a Tab-layout when i touched first fragment(tab) it required scrolling its working fine but when i touched second fragment(tab) i don't want collapsing toolbar-layout only two fragments tabs i want in that tab so help me if you know this.XML containing
enter code here
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#424242"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
app:layout_collapseMode="pin"
/>
<Relative-layout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
">
<Text-view
/>
<Text-view
/>
<View
android:id="#+id/view"
android:layout_width="wrap_content"
android:layout_height="2dp"
/>
<Image View
/>
</RelativeLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tabs
android:layout_gravity="bottom"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
/>
Set a TabSelected listener, and when your second tab is selected, collapse the toolbar via appBarLayout.SetExpanded(false, true);, and set it's height to be smaller.
See here and here.
This Fragment is an instance of a TabViewPager. I am having a issue with the FAB button. Now the problem that I am facing is the FAB button is not fully visible. Its half of the portion is hidden as shown in the screenshot below. Can any one help me to solve this issue. Thanks in advance.
!(http://i.imgur.com/qyT4ptm.png)
!(http://i.imgur.com/RxRS1Gn.png)
my activity_main.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.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"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_below="#+id/toolbar"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_below="#id/appBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
my Fragment_activity file
<?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"
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="false"
android:id="#+id/fabBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:src="#drawable/ic_plus"
app:fabSize="normal"
app:backgroundTint="#C2185B"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
/>
</FrameLayout>
I'm writing a view for styling my application's ActionBar,while it works perfectly in portrait,in landscape it clips the a line which is anchored to the bottom? Is it because ActionBar is assigned a certain height and my custom view is bigger than this? here's the XML for my custom view:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#252525" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ac_logo" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_weight="1"
android:background="#F0C46C" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_weight="1"
android:background="#FFFFFF" >
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="#drawable/ac_text" />
ok I figured it out, I'll post it just in case it helps anyones that happens to see this :)
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#252525" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:src="#drawable/ac_logo" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="#drawable/ac_text" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_weight="1"
android:background="#F0C46C" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_weight="1"
android:background="#FFFFFF" >
</LinearLayout>
</LinearLayout>
I want to align the spinner to left. spinner is not used for navigation here
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="#color/white"
android:textStyle="bold"/>
how to do it.
Grab the actionbar, then:
actionbar.setDisplayShowTitleEnabled(false);
Hi have already several apps with AdView, but this time, I can't see what is wrong.
When I look at the file in Eclipse in Graphical Layout, it shows the AdView placeholder in the right size and place but with the Error message:
Could not initialize AdView. Required XML attribute, "adSize" missing.
Please take a look on my code and hopefully somebody see what I'm missing.
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/eifelturm"
android:orientation="vertical" >
<Button
android:id="#+id/newbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/ic_menu_camera"
android:text="#string/neuesFoto"
android:gravity="fill"
android:onClick="newPhoto"
></Button>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/main_listview">
</ListView>
</LinearLayout>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
app:adSize="BANNER"
app:adUnitId="a1501d20d464e5d"
app:loadAdOnCreate="true" />
</RelativeLayout>
A little late to reply, but I think your problem was that you were using the keyword app instead of ads in your AdView definition. With this structure it should work:
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="a1501d20d464e5d"
ads:loadAdOnCreate="true" />