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>
Related
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"
i am trying to add a custom tool bar
this is my toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:subtitleTextColor="#color/sub_text_color"
app:navigationContentDescription="#string/abc_action_bar_up_description"
android:background="#color/sub_text_color"
app:navigationIcon="?attr/homeAsUpIndicator"
/>
this is my style
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
i have included it in my activity main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myproj.activities.RegisterActivity">
<include layout="#layout/toolbar"/>
in my main activity class i called
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle(R.string.create_account);
}
but still i am not able to see the toolbar in my class.
Can some one help me to figure out the error
Use LinearLayout as parent , the child layout might be hiding the toolBar
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myproj.activities.RegisterActivity">
<include layout="#layout/toolbar"/>
//other childs
</LinearLayout>
To set title to tool bar use getSupportActionBar().setTitle(title);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(title);
Quite a number of things could be responsible for this.
Firstly, It is possible that the views placed after the custom toolbar are overlayed on it, hence blocking it from view. Remenber that you are using RelativeLayout as your root element. So you'll want to ensure that views after the toolbar have android:layout_below="#+id/toolbar" attribute.
Secondly, I'll advice you to use a coordinator layout as your rootview and wrap your custom toolbar in AppBarLayout view. So that your layout file resembles this:
<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"
tools:context="ng.shoppi.lafarge_app.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
android:id="#+id/content_main"
layout="#layout/content_main" />
This will keep the toolbar at the top and ensure other views are below the toolbar.
Goodluck.
Try this,
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/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="?actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<com.itc.classmate.utils.FontTextView
android:id="#+id/textview_toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/gap_btn_logo"
android:layout_toLeftOf="#+id/rel_toolbar_options"
android:ellipsize="marquee"
android:paddingRight="5dp"
android:singleLine="true"
android:text=""
android:textColor="#color/colorWhite"
android:textSize="#dimen/comm_text_size_normal" />
<LinearLayout
android:id="#+id/rel_toolbar_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/rel_toolbar_right_cornor_item"
android:gravity="center_vertical">
<ImageView
android:id="#+id/imgview_toolbar_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="#dimen/toolbar_notification_right_margin"
android:layout_toLeftOf="#+id/imgview_toolbar_choose_class"
android:padding="#dimen/inc_toolbar_icon_padding"
android:src="#drawable/ic_menu_share"
android:visibility="gone" />
<ImageView
android:id="#+id/imgview_toolbar_choose_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="#dimen/toolbar_notification_right_margin"
android:layout_toLeftOf="#+id/imgview_toolbar_edit"
android:padding="#dimen/inc_toolbar_icon_padding"
android:src="#drawable/selectclass"
android:visibility="gone" />
<ImageView
android:id="#+id/imgview_toolbar_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="#dimen/toolbar_notification_right_margin"
android:layout_toLeftOf="#+id/imgview_toolbar_done"
android:padding="#dimen/inc_toolbar_icon_padding"
android:src="#drawable/profile_edit_icon"
android:visibility="gone" />
<ImageView
android:id="#+id/imgview_toolbar_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="14dp"
android:layout_toLeftOf="#+id/textview_toolbar_delete_bookmark"
android:padding="#dimen/inc_toolbar_icon_padding"
android:src="#drawable/done"
android:visibility="gone" />
<com.itc.classmate.utils.FontTextView
android:id="#+id/textview_toolbar_delete_bookmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="14dp"
android:layout_toLeftOf="#+id/imageview_toolbar_delete"
android:padding="#dimen/inc_toolbar_icon_padding"
android:text="#string/clear_all"
android:textColor="#color/colorWhite"
android:textSize="#dimen/comm_text_size_mediam"
android:visibility="gone" />
<ImageView
android:id="#+id/imageview_toolbar_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="14dp"
android:layout_toLeftOf="#+id/textview_toolbar_done"
android:padding="#dimen/inc_toolbar_icon_padding"
android:src="#drawable/delete"
android:visibility="gone" />
<com.itc.classmate.utils.FontTextView
android:id="#+id/textview_toolbar_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="#dimen/toolbar_notification_right_margin"
android:layout_toLeftOf="#+id/imgview_toolbar_notification"
android:padding="#dimen/inc_toolbar_icon_padding"
android:text="Done"
android:textColor="#color/colorWhite"
android:textSize="#dimen/comm_text_size_normal"
android:visibility="gone"
app:textAllCaps="true" />
<RelativeLayout
android:id="#+id/rl_notification"
android:layout_width="wrap_content"
android:layout_height="?actionBarSize"
android:layout_marginRight="#dimen/toolbar_notification_right_margin"
>
<ImageView
android:id="#+id/imgview_toolbar_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="#dimen/inc_toolbar_icon_padding"
android:src="#drawable/bell"
android:visibility="gone" />
<TextView
android:id="#+id/txtview_toolbar_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorWhite"
android:background="#drawable/shape_notification_dot"
android:textSize="#dimen/comm_text_size_very_small"
android:padding="2dp"
android:gravity="center"
android:visibility="gone"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"/>
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/rel_toolbar_right_cornor_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="#dimen/toolbar_notification_right_margin"
android:padding="#dimen/inc_toolbar_icon_padding"
android:visibility="visible">
<com.itc.classmate.utils.CircularImage
android:id="#+id/imgview_toolbar_profile"
android:layout_width="#dimen/toolbar_profile_width_height"
android:layout_height="#dimen/toolbar_profile_width_height"
android:layout_centerInParent="true"
android:src="#drawable/profile_icon"
android:visibility="invisible" />
<com.itc.classmate.utils.FontTextView
android:id="#+id/textview_toolbar_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/save"
android:textColor="#color/colorWhite"
android:textSize="#dimen/comm_text_size_mediam"
android:visibility="gone"
app:textAllCaps="true" />
<ImageView
android:id="#+id/imgview_toolbar_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginRight="#dimen/toolbar_notification_right_margin"
android:padding="#dimen/inc_toolbar_icon_padding"
android:src="#drawable/profile_delete_icon"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Try to remove theme in your custom toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" //REMOVE THIS
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:subtitleTextColor="#color/sub_text_color"
app:navigationContentDescription="#string/abc_action_bar_up_description"
android:background="#color/sub_text_color"
app:navigationIcon="?attr/homeAsUpIndicator"
/>
i think the theme is influential....
Please update your code a bit:
Style:
<style name="AppTheme" parent="Theme.AppCompat.Light">
XML file:
<android.support.design.widget.AppBarLayout
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:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
I tried this answer, but I could not achieve the same look & behavior as my current main activity.
What changes should I make to my existing main activity to add a fixed tab bar pinned to top with scrolled content like in the image below?
Here's a .GIF of my current main activity: i.stack.imgur.com/Yj0cv.gif
Here's a link to the full project called android: https://github.com/firebase/friendlychat/tree/master/android
Here's styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorButtonNormal">#drawable/button_selector</item>
<item name="colorButtonNormal">#drawable/button_selector</item>
<item name="android:buttonStyle">#style/FriendlyButtonStyle</item>
</style>
<style name="FriendlyButtonStyle" parent="Widget.AppCompat.Button">
<item name="android:textColor">#color/colorTitle</item>
</style>
</resources>
Here's activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.google.firebase.codelab.friendlychat.MainActivity">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
<android.support.v7.widget.RecyclerView
android:id="#+id/messageRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout"
android:layout_below="#+id/adView"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout">
<ImageView
android:id="#+id/addMessageImageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_add_black_24dp"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/messageEditText"
android:layout_gravity="center_vertical"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SEND"
android:enabled="false"
android:id="#+id/sendButton"
android:layout_gravity="bottom"/>
</LinearLayout>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Put your fixed view's in RelativeLayout and move scrolling content inside CoordinatorLayout. Like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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:layoutDirection="ltr"
tools:context=".MainActivity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout">
<android.support.design.widget.AppBarLayout
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"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.PopupOverlay"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
<android.support.v7.widget.RecyclerView
android:id="#+id/messageRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:layout_below="#+id/adView" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal">
<ImageView
android:id="#+id/addMessageImageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_add_black_24dp" />
<EditText
android:id="#+id/messageEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:enabled="false"
android:text="SEND" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Google has Design support library and with it you can implement Collapsing Toolbar and you do not need any 3rd party libraries!!
In addition to pinning a view, you can use app:layout_collapseMode="parallax" (and optionally app:layout_collapseParallaxMultiplier="0.7" to set the parallax multiplier) to implement parallax scrolling (say of a sibling ImageView within the CollapsingToolbarLayout)
And as example you can use this:
<android.support.design.widget.AppBarLayout
android:layout_height="186dp"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
And do not forget to add compile "com.android.support:design:25.3.1" in your module build.gradle
UPDATE 1:
First of all, you need to create a CoordinatorLayout.
All the new components use a new concept called Behavior that is used by the Coordinator Layout to take some actions based on different interactions.
<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:fitsSystemWindows="true">
</android.support.design.widget.CoordinatorLayout>
You can use fitsSystemWindows on any item you want to be painted below the status bar.
Then you need to add an AppBarLayout:
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
</android.support.design.widget.AppBarLayout>
And then inside that, you can add something like:
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
Just created behavior, what you want. Shouldn't be so complicated. So here is main XML for all Views. But I also have already created project for this sample, please write here, if I need to share full project.
SCREENS
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"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<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"
app:elevation="0dp">
<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.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:scrollbars="none"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
TO YOUR EXAMPLE
I share here another example, which should suite your code. I attached all view Ids for your examples. Check it.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<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"
app:elevation="0dp">
<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" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#+id/toolbar"
android:layout_centerHorizontal="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
app:layout_collapseMode="pin"></com.google.android.gms.ads.AdView>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="#+id/messageRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom |center_horizontal"
android:layout_marginBottom="100dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/addMessageImageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#android:drawable/ic_dialog_alert" />
<EditText
android:id="#+id/messageEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:enabled="false"
android:text="SEND" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_centerHorizontal="true"
android:layout_marginBottom="100dp"
android:layout_centerVertical="true" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
try above code
Style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorButtonNormal">#drawable/button_selector</item>
<item name="colorButtonNormal">#drawable/button_selector</item>
<item name="android:buttonStyle">#style/FriendlyButtonStyle</item>
</style>
<style name="FriendlyButtonStyle" parent="Widget.AppCompat.Button">
<item name="android:textColor">#color/colorTitle</item>
</style>
here if you don't want to change property to 'NoActionBar' then alternatively set it in AndroidManifest.xml file like above
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.NoActionBar"/>
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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.google.firebase.codelab.friendlychat.MainActivity"
android:id="#+id/coordinatorLayout">
<android.support.design.widget.AppBarLayout
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/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="center"
app:tabTextAppearance="#android:style/TextAppearance.Widget.TabWidget"
app:tabSelectedTextColor="#android:color/white"
app:tabTextColor="#android:color/white"
app:tabIndicatorHeight="2dp"
app:tabIndicatorColor="#android:color/white"/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.google.firebase.codelab.friendlychat.MainActivity">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
<include
layout="#layout/maincontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"/>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal"
android:layout_marginBottom="50dp">
<ImageView
android:id="#+id/addMessageImageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_add_black_24dp"/>
<EditText
android:id="#+id/messageEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"/>
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:enabled="false"
android:text="SEND"/>
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
maincontent.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/messageRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
I am trying to figure out hw to remove padding from FUllscreen dialog
below is styles which we are using while creating dialog object :
<style name="full_screen_dialog" parent="#android:style/Theme.Dialog">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:padding">0dp</item>
<item name="android:layout_margin">0dp</item>
<item name="android:layout_gravity">bottom</item>
<!-- Just to prove it's working -->
<item name="android:background">#00000000</item>
</style>
below is the dialog content
<?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="match_parent"
android:orientation="vertical"
android:id="#+id/main_content"
>
<RelativeLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layout1"
>
<com.theartofdev.edmodo.cropper.CropImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cropImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
app:cropAspectRatioX="5"
app:cropAspectRatioY="5"
app:cropShape="oval" />
</RelativeLayout>
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="100">
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:background="#a9aeac"
android:clickable="true"
android:focusable="true"
android:text="Cancel"
android:textColor="#000000" />
<Button
android:id="#+id/submit"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:background="#a9aeac"
android:clickable="true"
android:focusable="true"
android:text="Done"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
How to remove padding i have set the style but its not working
Following the codes:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.your_dialog_content);
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
can you try set layouts without style class in xml file?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/add_school_schoolname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/collegename"
android:inputType="textPersonName" />
<EditText
android:id="#+id/add_school_schoolweb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/collegeweb"
android:inputType="textPersonName" />
<Button
android:id="#+id/add_school_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Submit" />
</LinearLayout>
</LinearLayout>
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")));