Navigation View in specific activity - java

I have a problem with Navigation View located under Toolbar. I've read that to set it up correctly apps should use Fragments instead of Activities, but unfortunately I think that it's not my case, coz the whole app is already written using Activities.
I could make NavView work nice in MainActivity (because toolbar is added in it's xml), but the problem is that I don't need NavView on start screen, only in specific activity.
Is it possible to add NavView to only one activity correctly without moving to Fragments?
MainActivity.xml (where it worked perfectly):
<android.support.design.widget.CoordinatorLayout
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="#drawable/bg"
tools:context="ru.asmodeoux.g_lounge.MainActivity">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="59dp"
android:layout_height="59dp"
android:layout_gravity="top|left"
android:layout_margin="#dimen/fab_margin"
app:backgroundTint="#color/FAB_color"
app:elevation="24dp"
app:layout_anchor="#+id/include"
app:layout_anchorGravity="bottom|right"
app:srcCompat="#drawable/call" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="44dp"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="0dp"
android:minHeight="0dp"
android:textAlignment="center"
app:popupTheme="#style/AppTheme.AppBarOverlay" />
</android.support.design.widget.AppBarLayout>
<include
android:id="#+id/include"
layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
aboutProduct.xml (where I need to show NavNiew):
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false">
<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:background="#drawable/bg">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#drawable/bg"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/productRoot"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:id="#+id/productImg"
/>
<TextView
android:id="#+id/productDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/productImg"
android:layout_marginBottom="75dp"
android:layout_marginTop="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Place for product description."
android:textAlignment="textStart"
android:textColor="#color/white"
android:textSize="19sp"
android:textStyle="italic" />
</RelativeLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/productAdd"
android:layout_width="59dp"
android:layout_height="59dp"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:backgroundTint="#color/FAB_color"
android:elevation="24dp"
app:srcCompat="#drawable/buy" />
<TextView
android:id="#+id/productPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginBottom="#dimen/fab_margin"
android:background="#drawable/rectangle_rounded_some"
android:layout_marginLeft="#dimen/fab_margin"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="100 руб."
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="37sp" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
app:headerLayout="#layout/navigation_header"
android:background="#color/white"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/drawer" />
</android.support.v4.widget.DrawerLayout>
Header layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/gray">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:text="Что-то ещё?"
android:layout_marginStart="14dp"
android:textColor="#color/white"
android:textAlignment="textStart"
android:layout_marginBottom="8dp"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
And a screenshot of how NavView in "aboutProduct" class looks now here
And how it should look like here

As a result I think that the easiest way is to set toolbar there in Theme Editor to "NoActionBar" and add toolbar to every activity by hands.

Related

android Bottom app bar is not taking full width even after setting width to match parent

My bottom app bar is holding bottom navigation view and its shoqing little black strip on left side(pls check Screenshot
) even after setting width to match_parent.
It works fine when I use bottom navigation view without bottom app bar but I want both of them together,
I have tried setting margins right but still it does not move to left and take full width.
My layout file is below,
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.recipeapp.marathi.activities.HomeActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbarHome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:title="#string/app_name"
app:titleTextColor="#color/black" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/content_main" />
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="?attr/actionBarSize"
ads:adSize="BANNER"
ads:adUnitId="#string/admob_banner_adunit_id">
</com.google.android.gms.ads.AdView>
<com.google.android.material.bottomappbar.BottomAppBar
android:background="#color/white"
android:id="#+id/bottomappbar"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fabCradleMargin="10dp"
app:fabCradleRoundedCornerRadius="10dp"
app:fabCradleVerticalOffset="10dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
app:itemIconTint="#color/bottom_nav_item"
app:itemTextColor="#color/bottom_nav_item"
app:menu="#menu/nav_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/todo"
android:src="#drawable/ic_share"
app:layout_anchor="#id/bottomappbar"
app:layout_anchorGravity="bottom|center" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:background="#drawable/round_nav"
android:foreground="?attr/selectableItemBackground"
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:visibility="visible"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/menu_drawer_navigation" />
</androidx.drawerlayout.widget.DrawerLayout>
please help..
Relevant documentation
This question has also been awnsered here and here
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
in your com.google.android.material.bottomappbar.BottomAppBar is but far the simplest
Sample code:
<com.google.android.material.bottomappbar.BottomAppBar
android:background="#color/white"
android:id="#+id/bottomappbar"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fabCradleMargin="10dp"
app:fabCradleRoundedCornerRadius="10dp"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:fabCradleVerticalOffset="10dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
app:itemIconTint="#color/bottom_nav_item"
app:itemTextColor="#color/bottom_nav_item"
app:menu="#menu/menu_drawer_navigation"
/>
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher_background"
app:layout_anchor="#id/bottomappbar"
app:layout_anchorGravity="bottom|center" />

Fragment going over ActionBar in ViewPager

I am using viewpager to show different fragments but in this one of fragment replaces the actionbar. Till now I have found that it is because of edittext which I am using for searching items. When I remove edittext from this it works fine.
The main activity layout is a CoordinatorLayout, containing the typical AppBarLayout and then a ViewPager and it is filling whole screen.
fragment_gst_rates.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="5dp"
tools:context="com.kamalarora.mygst.FragmentGstRates">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/searchBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search items . . ."
android:layout_marginTop="5dp"
android:layout_marginBottom="2dp"
android:drawableRight="#android:drawable/ic_menu_search"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/lightGrey">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Products"
android:textSize="18dp"
android:layout_marginLeft="1dp"
android:padding="5dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GST Rate"
android:layout_marginRight="1dp"
android:textSize="18dp"
android:gravity="right"
android:padding="3dp"/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/listView">
</ListView>
</LinearLayout>
</LinearLayout>
activity_main.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:tools="http://schemas.android.com/tools"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.kamalarora.mygst.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<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/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<View
android:id="#+id/appbar_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/transparent"
android:visibility="invisible" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="104dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottomNav"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app:itemBackground="#color/white"
app:itemIconTint="#color/mediumgrey"
app:itemTextColor="#color/mediumgrey"
app:menu="#menu/menu_bottom" />
<!--<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" /> -->
</android.support.design.widget.CoordinatorLayout>
do you tried with the linear layout at the root there try change with android:layout_height="wrap_content" .

java android : resize appbarlayout when hide a specific relativelayout

I have a bug in android development.
I would like resize the appbarlayout when I hide a relative layout Contained in it. but the height of appbarlayout is not reloaded and so I have a bar blue.
Here is the result obtained :
I hide this relative layout when my adapter is empty.
Do you have any idea how to remedy this?
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:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:background="?attr/colorPrimary"/>
/// I want hide this Relative Layout
<RelativeLayout
android:id="#+id/header_recycler_view"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/header_set_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="#style/Base.TextAppearance.AppCompat.Subhead" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:onClick="onClickToScrollToBegin"
android:clickable="true"
android:drawableRight="#drawable/ic_double_arrow_up" />
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
app:layout_behavior = "#string/appbar_scrolling_view_behavior"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_recycler_view"
android:scrollbars="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchorGravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:layout_anchor="#+id/rv_recycler_view"
app:layout_behavior="com.brick_reader.brick_reader.FABScrollBehavior"
app:srcCompat="#drawable/ic_search_white_24dp" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Thank you in advance for your answers.

Error when use android.support.design.widget.CoordinatorLayout

I'm new android dev. I have tried to work with
<android.support.design.widget.CoordinatorLayout>
and here is my XML code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ducbo.flynow_ver20.payment_section">
<LinearLayout
android:id="#+id/payment_header"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/background_header">
<Button
android:id="#+id/payment_btn_back"
android:layout_width="15dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:background="#drawable/btnback" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="27dp"
android:layout_toRightOf="#id/payment_btn_back"
android:layout_weight="12"
android:gravity="center_horizontal"
android:text="#string/thanh_toan"
android:textColor="#color/white"
android:textSize="28sp" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/payment_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_header">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/payment_types"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:padding="15dp"
android:text=""
android:textSize="16sp" />
<LinearLayout
android:id="#+id/payment_types_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/payment_tab_method"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/payment_types">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
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"-->
<!--app:layout_scrollFlags="scroll|enterAlways"-->
<!--app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />-->
<!--android:background="?attr/colorPrimary"-->
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="#color/white"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<include
android:id="#+id/payment_table_passenger"
layout="#layout/table_passenger"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_types_container"></include>
<include
android:id="#+id/payment_startdp"
layout="#layout/fm_booking_startdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_table_passenger"></include>
<include
android:id="#+id/payment_enddp"
layout="#layout/fragment_booking_enddp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_startdp">
</include>
<Button
android:id="#+id/payment_btn_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/payment_enddp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/border_orange"
android:text="Continue"
android:textColor="#color/white" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
With each tab, I used one fragment to show tab's content. After that, I included some layout below Coordinator but it wasn't appear below Coordinator. When I checked again in Design tab on Android studio, I realized that the height of coordinator seemingly unlimited even though I set wrap_content for it. I think that is problem and I have changed height attribute of Coordinator to specific number and my input layout appeared but I don't want like this. What can I fix the height of Coordinator to wrap content?

AppbarLayout with Toolbar, Navigation Drawer, and tabs

I'm developing an app that has a Main Activity and a Navigation Drawer to switch between different fragments inside the Main Activity.
One of the fragments contains a tab layout.
My layouts are a mess and they don't behave or perform properly.
Here is my XML:
Main:
<android.support.v4.widget.DrawerLayout 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:layout_gravity="right"
android:fitsSystemWindows="true"
android:clickable="true"
android:layoutDirection="rtl"
android:id="#+id/drawer_layout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl"
android:background="#EEEEEE"
android:clickable="true">
<include
android:id="#+id/toolbar"
android:gravity="right"
layout="#layout/toolbar"
android:clickable="true" />
<FrameLayout
android:id="#+id/content_frame"
android:layout_below="#id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/mainFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_gravity="bottom|end"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:layout_marginTop="5dp"
android:elevation="8dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorAccent"
android:src="#drawable/ic_perm_phone_msg_white_24px" />
<LinearLayout
android:id="#+id/miniFabFrame"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_alignParentLeft="true"
android:layout_gravity="bottom|end"
android:layout_marginLeft="20dp"
android:layout_above="#id/mainFab"
android:padding="0dp">
<android.support.design.widget.FloatingActionButton
android:id="#+id/messageFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:elevation="8dp"
android:layout_marginTop="5dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorPrimary"
app:fabSize="mini"
android:src="#drawable/ic_textSMS_white_24px" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/callFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:elevation="8dp"
app:pressedTranslationZ="12dp"
app:backgroundTint="?android:colorPrimary"
app:fabSize="mini"
android:src="#drawable/ic_call_white_24px" />
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:id="#+id/nav_view"
android:layoutDirection="rtl"
app:headerLayout="#layout/header"
app:menu="#menu/nav_menu" />
</android.support.v4.widget.DrawerLayout>
Tabs Fragment:
<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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:id="#+id/halachot_layout"
android:layoutDirection="ltr">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.refractored.PagerSlidingTabStrip
android:id="#+id/halachotTabs"
android:layout_below="#id/halachot_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
pstsPaddingMiddle="false"
app:pstsShouldExpand="true" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/halachotPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
I want to use Coordinator Layout in my Main layout, and use AppBarLayout to wrap the Toolbar, although I don't know how to use them.
If someone could please help me organize my layout properly, with some explanations of how this works and what I am doing wrong, I would appreciate it very very much.
Thanks!
Firstly create an activity layout which contains Navigation Drawer and ToolBar
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
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/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:background="#drawable/ab_bg2"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="#style/Base.TextAppearance.AppCompat.Subhead"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginBottom="40dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:contentInsetStart="0dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginRight="3dp"
android:layout_marginTop="5dp"
android:background="#drawable/linlayoutshape_shadow"
android:tag="#string/layout_default"/>
</android.support.design.widget.CoordinatorLayout>
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#color/Drawer_bg"
android:choiceMode="singleChoice"
android:divider="#color/Drawer_bg"
android:dividerHeight="10dp"
android:listSelector="#drawable/list_selector"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" />
Now create a Fragment which will show your Tab layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.utils.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#drawable/background_tab"
app:pstsShouldExpand="true" />
<com.utils.CustomViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linHeader"
android:background="#drawable/background_tab"
tools:context=".TestBoardActivity" />
</RelativeLayout>

Categories