Hi I have a BottomNavigationView but it adds a default space to the start.Below is my code.
XML:
<?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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textAlignment="center"
android:textSize="25dp"
android:id="#+id/message"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="Home"
/>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="#+id/app_bar_layout"
>
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/home_toolbar"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemBackground="#android:color/holo_green_dark"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/bottom_nav_menu" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
This is my menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_home"
android:icon="#drawable/home"
android:title="#string/title_home"
/>
<item
android:id="#+id/navigation_search"
android:icon="#drawable/search"
android:title="#string/title_dashboard" />
<item
android:id="#+id/nav_add_post"
android:icon="#drawable/add"
android:title="#string/title_notifications" />
<item
android:id="#+id/navigation_notifications"
android:icon="#drawable/heart"
android:title="#string/title_notifications" />
<item
android:id="#+id/nav_profile"
android:icon="#drawable/profile_icon"
android:title="#string/title_notifications" />
</menu>
This is how it looks when i run.
I have referred to this post : Bottom Navigation View With Left Righ Space Issue, but it didn't help
me resolve the issue and i also tried app:itemBackground="#android:color/holo_green_dark" which also
didn't solve my spacing issue.
You can remove the Toolbar if you don't need it and it will work normally , or if you need it then do the following
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/home_toolbar"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"// this value which removes the space
app:contentInsetLeft="0dp"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemBackground="#android:color/holo_green_dark"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/pop_up" />
</androidx.appcompat.widget.Toolbar>
Add this values in you parent component
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
Related
I want to have toolbar with corner radius in the bottom edges.I create a drawable background for this perpous. But there is a problem.The bottom corner of the toolbar, show withe spaces.I set same background color for the root of layout and AppBarLayout, But when scroll through screen white spaces still is showed. I try different solution like set this style for the AppBarLayout but not work.
<!-- style appbar home -->
<style name="appbar_style" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
This is drawable of toolbar background:
<shape android:shape="rectangle">
<gradient
android:type="linear"
android:angle="0"
android:startColor="#EA4D13"
android:endColor="#FD7920" />
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"/>
</shape>
This is my fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layoutDirection="rtl">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/grey8"
android:fitsSystemWindows="true">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/drw_bg_toolbar_orange"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:src="#drawable/ic_search" />
<ImageView
android:id="#+id/img_instagram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:src="#drawable/ic_instagram" />
<TextView
android:id="#+id/txt_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/img_instagram"
android:layout_toRightOf="#+id/img_search"
android:gravity="center"
android:text="#string/home_title"
android:textColor="#color/white" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey8">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rcy_hot_post"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/img_retry"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/img_retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:src="#drawable/ic_refresh"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ProgressBar
android:id="#+id/progressbar"
style="#style/Widget.MaterialComponents.ProgressIndicator.Circular.Indeterminate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
try to set AppBarLayout's background to #android:color/transparent
You should add android:layout_marginTop="-15" to SwipeRefreshLayout then add an empty View with that Value Height as much as you Specified in android:layout_marginTop="15" (positive value) your RecyclerView
something like this:
<androidx.coordinatorlayout.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:layoutDirection="rtl">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/grey8"
android:fitsSystemWindows="true">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/drw_bg_toolbar_orange"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:src="#drawable/ic_search" />
<ImageView
android:id="#+id/img_instagram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:src="#drawable/ic_instagram" />
<TextView
android:id="#+id/txt_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/img_instagram"
android:layout_toRightOf="#+id/img_search"
android:gravity="center"
android:text="#string/home_title"
android:textColor="#color/white" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-15dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey8">
<View
android:id="#+id/emptySpace"
android:layout_width="match_parent"
android:layout_height="15dp"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rcy_hot_post"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/img_retry"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/emptySpace" />
<ImageView
android:id="#+id/img_retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:src="#drawable/ic_refresh"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ProgressBar
android:id="#+id/progressbar"
style="#style/Widget.MaterialComponents.ProgressIndicator.Circular.Indeterminate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
improving on #mohammad's answer. You must change the order of CoordinatorLayout's components.
Check this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layoutDirection="rtl">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-30dp" // it's better to set the same value as the corner radius used in the header shape.
android:paddingTop="30dp" // same here, use the identical values to maintain the same height.
app:layout_behavior="#string/appbar_scrolling_view_behavior">
// other code..
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/grey8"
android:fitsSystemWindows="true">
// other code..
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I am using BottomNavigationView with ConstraintLayout. Now the issue is when I click on the second item all view getting down hiding it.
Before Click
After Click
<android.support.constraint.ConstraintLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="56dp"
android:text="#string/title_home"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_home"
android:icon="#mipmap/home_icon"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_dashboard"
android:icon="#mipmap/my_order"
android:title="My Order" />
<item
android:id="#+id/navigation_notifications"
android:icon="#mipmap/home_earning"
android:title="Earnings" />
<item
android:id="#+id/navigation_dashboard1"
android:icon="#mipmap/cart_icon"
android:title="Cart" />
<item
android:id="#+id/navigation_notifications2"
android:icon="#mipmap/account_icon"
android:title="Account" />
</menu>
I had similar problem with ConstraintLayout. You can try this.
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/container">
<android.support.design.widget.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="#android:color/white"
app:elevation="8dp"
app:menu="#menu/navigation"
android:layout_alignParentBottom="true">
</android.support.design.widget.BottomNavigationView>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:layout_above="#+id/bottom_navigation" />
</RelativeLayout>
You don't need to have LinearLayout for this. Use app:layout_constraintBottom_toBottomOf="parent" to move the navigation view to bottom.
<android.support.constraint.ConstraintLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
app:layout_constraintBottom_toBottomOf="parent"
app:labelVisibilityMode="labeled"
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="#menu/navigation_contractor" />
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="#string/title_home"
app:layout_constraintBottom_toTopOf="#+id/navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0"/>
</android.support.constraint.ConstraintLayout>
I found the issue for this, I have set in my home fragment android:fitsSystemWindows="true", I removed it and it works well.
Main Activity and Chat Activity use the same theme:
<activity
android:name=".View.MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".View.ChatActivity"
android:label="#string/title_activity_chat"
android:parentActivityName=".View.MainActivity"
android:theme="#style/AppTheme.NoActionBar"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ocm.my.chat.View.MainActivity"/>
</activity>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/statusTranGray </item>
</style>
However the status bars' color are different:
I cannot figure out why this odd thing happen, please help.
color.xml
activity_chat.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:fitsSystemWindows="true"
tools:context="ocm.my.chat.View.ChatActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/chat_toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:background="?attr/colorPrimary"
android:title="fsdasdfsda"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1"/>
<include
android:id="#+id/include"
layout="#layout/content_chat"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/chat_toolbar"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1"/>
</android.support.constraint.ConstraintLayout>
content_chat.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<EditText
android:id="#+id/msg_type"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:hint="Input message"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.75"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/btn_chat_send"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"/>
<Button
android:id="#+id/btn_chat_send"
android:layout_width="88dp"
android:layout_height="0dp"
android:background="#color/background_floating_material_dark"
android:text="Send"
android:textColor="#color/background_material_light"
app:layout_constraintBottom_toBottomOf="#+id/msg_type"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintVertical_bias="0.0"/>
<ListView
android:id="#+id/list_msg"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:divider="#null"
android:listSelector="#android:color/transparent"
android:transcriptMode="alwaysScroll"
app:layout_constraintBottom_toTopOf="#+id/msg_type"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"/>
</android.support.constraint.ConstraintLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<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>
app_bar_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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="ocm.my.chat.View.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/stat_notify_chat"/>
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ocm.my.chat.View.MainActivity"
tools:showIn="#layout/app_bar_main">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintBottom_creator="1">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
Addition
Change android:statusBarColor property to red color. Both the two activity status bars' color look the same. Both red.
I have the following layout which basically displays two editTexts
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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:fillViewport="true"
android:layout_gravity="fill_vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="global.sti.attendance.LogInActivity"
tools:showIn="#layout/activity_log_in">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical"
android:paddingTop="150dp"
android:paddingBottom="50dp">
<EditText
style="#style/TextField"
android:id="#+id/userNameET"
android:hint="Enter username"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="#drawable/ic_user"
android:background="#drawable/custom_textfield"/>
<EditText
style="#style/TextField"
android:id="#+id/passwordET"
android:hint="Enter password"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="#drawable/ic_lock"
android:background="#drawable/custom_textfield"/>
<Button
style="#style/Button"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log-in"
android:id="#+id/loginButton"
android:layout_gravity="center_horizontal"
android:width="180dp" />
<Button
style="#style/Button"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SIGN-UP!"
android:id="#+id/signUpButton"
android:layout_gravity="center_horizontal"
android:width="180dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
This is my activity_log_in.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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="global.sti.attendance.LogInActivity">
<android.support.design.widget.AppBarLayout
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"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_log_in" />
</android.support.design.widget.CoordinatorLayout>
And this is my TextField style:
<style name="TextField">
<item name="android:textColor">#color/colorPrimary</item>
<item name="android:textCursorDrawable">#null</item>
<item name="android:paddingTop">10dp</item>
<item name="android:paddingBottom">10dp</item>
<item name="android:drawablePadding">10dp</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:height">40dp</item>
</style>
The problem is when I click on one of the editTexts and the keypad is showing, it blocks my views, I would expect the NestedScrollView will allow me to scroll up but it does not.
What seems to be the problem? Thanks!
Add this to your activity in the AndroidManifest.xml:
android:windowSoftInputMode="stateVisible|adjustResize"
Example:
<activity
android:name=".LogInActivity"
android:windowSoftInputMode="stateVisible|adjustResize">
<!-- Intent-filters if any -->
</activity>
I have this bottom action bar style
I want to design like this (left , center, right) with background color blue or red
this is the menu
<menu 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" tools:context=".MainActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="#+id/menu_save"
android:icon="#drawable/ic_action_picture"
android:title="Save"
app:showAsAction="always"/>
<item android:id="#+id/menu_search"
android:icon="#drawable/ic_action_picture"
android:title="Search"
app:showAsAction="always"/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_picture"
android:title="Share"
app:showAsAction="always"
/>
</menu>
If you need anything else ask me
If you have not solved your issue, you can refer to the following:
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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
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"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentBottom="true"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/button1"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="0.175"
android:background="#android:color/transparent"
android:src="#drawable/ic_action_back" />
<View
android:id="#+id/view1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.1" />
<ImageButton
android:id="#+id/button2"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="0.175"
android:background="#android:color/transparent"
android:src="#drawable/ic_action_cloud" />
<View
android:id="#+id/view2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#android:color/transparent" />
<ImageButton
android:id="#+id/button3"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="0.175"
android:background="#android:color/transparent"
android:src="#drawable/ic_action_copy" />
<View
android:id="#+id/view3"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#android:color/transparent" />
<ImageButton
android:id="#+id/button4"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="0.175"
android:background="#android:color/transparent"
android:src="#drawable/ic_action_help" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Here you can download the needed icons:
https://www.google.com/design/icons/index.html
The distance between the icons can you make with a custom android:actionButtonStyle like:
<item name="android:actionButtonStyle">#style/ActionButtonStyle</item>
<style name="ActionButtonStyle" parent="#android:style/Widget.Holo.Light.ActionButton">
<item name="android:minWidth">70dip</item>
<item name="android:paddingLeft">70dip</item>
<item name="android:paddingRight">70dip</item>
</style>
And the background color:
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FF0000")));