setting customView in actionBar - android-actionbar

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>

Related

Android Navigation Component multiple NavHost implementation

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>

Hide parent activity collapsingToolbar layout from child fragments

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.

Tablayout height issue in landscape when inside AppBarLayout

My intention is to have the tabLayout inside an appBarLayout with a CollapsingToolbarLayout above. My problem is when i rotate the phone the tablayout height changes and i can't figure out why.
PS: i'am not handling by miself the orientation changes in this particular activity.
I'am using the last libraries:
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
My layout:
<RelativeLayout 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.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
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/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:id="#+id/backdrop_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/backdrop_image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<com.pnikosis.materialishprogress.ProgressWheel
android:id="#+id/backdrop_progressBar"
style="#style/MaterialProgressBar"/>
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:navigationIcon="#drawable/ic_menu_white_24dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:title=""
app:titleTextAppearance="#style/ToolbarText"/>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="none"
app:tabGravity="fill"
app:tabMode="fixed"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_wines"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<com.pnikosis.materialishprogress.ProgressWheel
android:id="#+id/loading_progressbar"
style="#style/MaterialProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/accent"
android:fitsSystemWindows="true"/>
</RelativeLayout>
Expected height:
Wrong height:

Floating Action Button not showing fully inside a fragment in Android-Design_library 22.2.0

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>

<com.google.ads.AdView gives me: Error parsing XML: unbound prefix

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" />