Fixed Footer in Android API 22 (Android 5.1 (Lollipop)) - android

I am new to Android and trying to develop an app with Android API 22. I am not able to get a fixed footer. How to make the footer fixed with scrollable content in the middle of the activity? What are attributes to set and how?
I have solution like - setting 'android:layout_alignParentBottom="true"' which might work for previous API levels but now obsolete.

Try android:layout_gravity="bottom", it works in my app.

I usually do it like this...
layout.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- The content: this is scrollable -->
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/footer"
style="#style/Footer"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true">
<!-- Stuff to go in your footer -->
</LinearLayout>
</RelativeLayout>
styles.xml
<style name="Footer" parent="Widget.AppCompat.ButtonBar" >
<item name="android:background">#android:color/white</item>
<item name="android:gravity">center_vertical|end</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">match_parent</item>
<item name="android:padding">4dp</item>
</style>
v21/styles:
<style name="AppTheme.LinearLayout.Footer" parent="Widget.AppCompat.ButtonBar" >
<item name="android:background">#android:color/white</item>
<item name="android:gravity">center_vertical|end</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">match_parent</item>
<item name="android:padding">4dp</item>
<item name="android:elevation">4dp</item>
</style>
This creates a nice-looking footer, with elevation on Lollipop+ devices.

You want to do something very similar to this:
<?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"
>
<ScrollView
android:layout_above="#+id/footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
</LinearLayout>
</RelativeLayout>

Related

Toolbar menu item text doesn't align with icon

How can I align text with the icon? It is working fine if I remove parent property but it is being used by some other activity so I cannot remove it. I think I might have messed up somewhere in layout xml file but couldn't find it out.
styles.xml
<style name="DarkToolbar" parent="Widget.AppCompat.Toolbar">
<item name="android:background">#color/whateever</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="colorControlNormal">#android:color/white</item>
</style>
<style name="LightPopupMenu">
<item name="android:background">#android:color/white</item>
<item name="android:textColor">#android:color/black</item>
<item name="overlapAnchor">false</item>
</style>
layout.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/c_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/window_background_dark">
<androidx.appcompat.widget.Toolbar
android:id="#+id/move_pick_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/DarkToolbar"
app:popupTheme="#style/LightPopupMenu"
android:elevation="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/move_wf_pick_toolbar_title"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
tools:text="Token: 123" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
<FrameLayout />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Current behaviour:
is there a way to achieve this without removing parent attribute?

Android Material CardView with full screen image on Cardview

i need to do this :
http://developer.android.com/design/material/images/card_travel.png
so i create and add the dependency to the project and here is my activity main code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/feed_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_margin="6dp">
<ImageView
android:layout_width="100dp"
android:layout_height="50dp"
android:src="#drawable/ic"/>
<TextView
style="#style/TextAppearance.AppCompat.Caption"
android:textColor="#555"
android:layout_margin="3dp"
android:gravity="end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Detail"/>
</android.support.v7.widget.CardView>
</LinearLayout>
so, how we can do this like below picture:?
http://i.stack.imgur.com/Z0lNa.png
Cheers!
What you're looking for is a translucent status bar. When you have this configured you're able achieve this effect. Make also sure to remove the actionbar as I do in my example down below, otherwise you'll have to make it transparent.
Change your v21/themes.xml file to this:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
Then add android:fitsSystemWindows="true" to your LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/feed_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">

AppCompat v22.1.1 button style api 16+

I'm trying to style the buttons with the new supportv7 v22.1.1
It works fine on device with Lollipop, but on older device, it doesn't apply the theme anymore.
The themes.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:buttonStyle">#style/Button</item>
</style>
<style name="Button" parent="Widget.AppCompat.Button">
<item name="android:textColor">#color/white</item>
<item name="android:background">#1FA561</item>
</style>
</resources>
the manifest does include android:theme="#style/AppTheme"
Basic layout file
<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"
android:gravity="center_horizontal"
android:orientation="vertical"
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=".LoginActivity">
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/email_sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</LinearLayout>
sorry to say this but, BUTTON style support not included in appcompat-v7
still want solution check this answer and you can also use any third party library for material button style

Navigation Drawer not occure on Status Bar

Actually i am trying to do navigation drawer but i want it on status bar not below it i put all kind of code to make it transparent but still don't work
My xml layout is like
<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="true"
android:elevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/actionbar_color"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"></android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/content_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/drawer_Linearlayout"
android:layout_width="260dp"
android:layout_gravity="start|top"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="168dp"
android:scaleType="fitXY"
android:src="#drawable/navigation_img"
android:id="#+id/mytext"/>
<ListView
android:id="#+id/navdrawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:layout_below="#+id/mytext"
android:layout_gravity="start|bottom"
android:background="#FFFFFF"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:listSelector="#drawable/list_selector"
android:paddingTop="5dp"></ListView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
My Theme is for v-21
<style name="AppThemes" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowTranslucentStatus">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="colorPrimary">#color/actionbar_color</item>
<item name="colorPrimaryDark">#color/alert_normal</item>
<item name="colorAccent">#color/actionbar_color</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
When i remove LinearLayout and ImageView it work fine but
i want imageview inside DrawerLayout but actually it supports only 2 child elements so i have to use LinearLayout
Please suggest me way to do that way.
I got solution for such layout.
Sorry for posting late. I just have to make a little change in xml just like that.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/app_bar"></include>
<FrameLayout
android:id="#+id/content_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/drawer_Linearlayout"
android:layout_width="260dp"
android:layout_gravity="left|start"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="168dp"
android:scaleType="fitXY"
android:src="#drawable/navigation_img"
android:id="#+id/mytext" />
<ListView
android:id="#+id/navdrawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:layout_below="#+id/mytext"
android:layout_gravity="start|bottom"
android:background="#FFFFFF"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:listSelector="#drawable/list_selector"
android:paddingTop="5dp"></ListView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
And also make your theme style for v-21 like that.
<!-- Base application theme. -->
<style name="AppThemes" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowTranslucentStatus">true</item>
<item name="colorPrimary">#color/actionbar_color</item>
<item name="android:textColor">#color/myNavigationColor</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="titleTextStyle">#style/ActionBarTitleText</item>
<item name="colorPrimaryDark">#color/actionbar_primary_color</item>
<item name="colorAccent">#color/actionbar_color</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
and normal theme style is like
<style name="AppThemes" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/actionbar_primary_color</item>
<item name="colorPrimary">#color/actionbar_color</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:textColor">#color/myNavigationColor</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
Hope if you get stuck in such situation, these will be the solution for you.
Try adding these lines to your android:id="#+id/drawer_Linearlayout"
The layout gravity should start from left to right, and make it fit by setting the android:fitsSystemWindowsattribute to true.
<LinearLayout
android:id="#+id/drawer_Linearlayout"
android:layout_width="260dp"
android:layout_gravity="left|start"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:orientation="vertical">

Problems getting my ActionModeBar(?) to overlap support toolbar

I have been trying to get my app to look more material(ized) with the help of app compat v21, I have replaced my regular actionbar with the support toolbar, and changed my theme to Theme.AppCompat.Light.NoActionBar this works great! However, when I longpress an item in my gridview and my actionmode bar (is that what they are called?) shows up for multi select it shows above the toolbar.
I want it to overlap the toolbar, the same way it did with my old regular actionbar. I have tried to find a solution here, and have found multiple sources saying to add true
This does not work for me, i have tried both with the android: prefix and without, but still I get the same result. My activity extends ActionBarActivity and I have put:
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
In my onCreate. I feel like I have tried anything but I get the same result regardless.
I guess I better show some code:
My main layout
<android.support.v4.widget.DrawerLayout
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?window_bg_default"
>
<!-- The main content view -->
<include layout="#layout/toolbar" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
ads:adSize="SMART_BANNER"
android:visibility="gone"
android:background="#color/text_darkgray"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content" />
<TableLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="#+id/main_content"
android:layout_above="#id/adView"
/>
</RelativeLayout>
</LinearLayout>
<!-- The navigation drawer -->
<include layout="#layout/navdrawer" />
My styles
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="colorPrimary">#color/twee_orange_light</item>
<item name="colorPrimaryDark">#color/twee_orange_dark</item>
<item name="colorAccent">#color/twee_blue_light</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionBarStyle">#style/AppTheme.Actionbar</item>
<item name="android:actionModeBackground">#color/twee_orange_dark</item>
<item name="android:actionOverflowButtonStyle">#style/AppTheme.Overflow</item>
<item name="android:homeAsUpIndicator">#drawable/ic_action_home</item>
<item name="card_bg_default">#drawable/img_bg_card</item>
<item name="window_bg_default">#drawable/window_background</item>
<item name="card_episode_name">#color/nextepisodegray</item>
<item name="card_episode_number">#color/twee_black</item>
<item name="button_bg">?android:attr/selectableItemBackground</item>
<item name="button_watched">#drawable/ic_watched_inactive</item>
<item name="text_default">#color/text_slightlydarkgray</item>
<item name="text_default_header">#color/text_darkergray</item>
<item name="text_season_separator">#color/black</item>
<item name="drawer_background">#color/drawer_background</item>
<item name="drawer_list_background">#color/drawer_list_background</item>
<item name="card_bg_default_color">#color/drawer_list_background</item>
<item name="twee_divider">#color/divider_default</item>
<item name="card_header_default">#drawable/img_bg_cardtop_header</item>
<item name="checkbox_watched">#drawable/checkbox_watched</item>
<item name="card_middle_bg">#drawable/background_listitem_default</item>
</style>
My toolbar:
<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"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/twee_orange_light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:elevation="8dp" />
My navdrawer:ยจ
<se.ja1984.twee.Activities.Views.ScrimInsetsScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="fill_parent"
android:layout_gravity="left|start"
android:orientation="vertical"
android:id="#+id/drawer_wrapper"
android:background="?drawer_background"
android:fitsSystemWindows="true"
app:insetForeground="#4000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="165dp"
android:background="#drawable/img_navdrawer_header"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="#dimen/navbar_top"
android:paddingBottom="8dp"
android:id="#+id/lnrProfileChooser"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/layoutImage"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginRight="#dimen/padding_small"
>
<se.ja1984.twee.utils.RoundedImageView
style="#style/Twee_Cast_Photo"
android:layout_height="64dp"
android:layout_width="64dp"
android:id="#+id/imgUser"
android:scaleType="centerCrop"
android:src="#drawable/ic_no_cast"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/traktWrapper"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="gone"
>
<ImageView
android:id="#+id/background"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/trakt_background"
/>
<ImageView
android:layout_gravity="center"
android:id="#+id/imgTraktLogo"
android:layout_width="10dp"
android:layout_height="10dp"
android:src="#drawable/ic_trakt_logo"
/>
</FrameLayout>
</RelativeLayout>
<it.sephiroth.android.library.widget.HListView
android:id="#+id/profiles"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right|top" />
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:layout_gravity="bottom"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_alignParentBottom="true"
>
<TextView
style="#style/Twee_Profile_Displayname"
android:id="#+id/txtUsername"
android:text="#string/profile_notsignedin_displayname"
android:paddingTop="0dp"
/>
<TextView
android:text="Xxxx hours well spent"
style="#style/Twee_Profile_Timewasted"
android:id="#+id/txtTimeWasted"
android:paddingTop="0dp"
android:layout_below="#+id/txtUsername" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
<LinearLayout
android:id="#+id/navdrawer_items_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical" />
</LinearLayout>
</se.ja1984.twee.Activities.Views.ScrimInsetsScrollView>
The trained eyes might see that I have borrowed the ScrimInsetScrollView from the IOSched app, but I don't think that matters.
And here's an image of the monsterosity!
I managed to solve this issue myself!
The problem is that I ran my super.onCreate() to late in my onCreate method.
I moved it to the top of my method, and now it works great!

Categories

Resources