<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Material Design Backward Compatibility Archives - Truiton</title>
	<atom:link href="https://www.truiton.com/tag/material-design-backward-compatibility/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Technology Reaching Us In Time - Online</description>
	<lastBuildDate>Thu, 21 Nov 2019 09:27:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.truiton.com/wp-content/uploads/2022/11/cropped-truiton_new_logo_half_white.png?fit=32%2C32&#038;ssl=1</url>
	<title>Material Design Backward Compatibility Archives - Truiton</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">54534495</site>	<item>
		<title>Android Chips Example: Material Design</title>
		<link>https://www.truiton.com/2018/10/android-chips-example-material-design/</link>
					<comments>https://www.truiton.com/2018/10/android-chips-example-material-design/#respond</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Sun, 21 Oct 2018 06:27:20 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Material Design]]></category>
		<category><![CDATA[Material Design Backward Compatibility]]></category>
		<guid isPermaLink="false">https://www.truiton.com/?p=2119</guid>

					<description><![CDATA[<p>Google&#8217;s material design has been evolving year by year. At first when Material Design was introduced a lot of new components were listed in its documentation. But their implementation or official widgets were not released at that time. But&#160;with every support library release, few new significant components are released. With this year&#8217;s Google I/O, Androidx&#8230;&#160;<a href="https://www.truiton.com/2018/10/android-chips-example-material-design/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Android Chips Example: Material Design</span></a></p>
<p>The post <a href="https://www.truiton.com/2018/10/android-chips-example-material-design/">Android Chips Example: Material Design</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter is-resized"><img data-recalc-dims="1" fetchpriority="high" decoding="async" data-attachment-id="2182" data-permalink="https://www.truiton.com/2018/10/android-chips-example-material-design/featured-android_chips/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Featured-Android_Chips.jpg?fit=950%2C530&amp;ssl=1" data-orig-size="950,530" data-comments-opened="1" data-image-title="Android Chips Example Featured" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Featured-Android_Chips.jpg?fit=950%2C530&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Featured-Android_Chips.jpg?resize=580%2C323&#038;ssl=1" alt="Android Chips Example Featured" class="wp-image-2182" width="580" height="323" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Featured-Android_Chips.jpg?w=950&amp;ssl=1 950w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Featured-Android_Chips.jpg?resize=300%2C167&amp;ssl=1 300w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Featured-Android_Chips.jpg?resize=768%2C428&amp;ssl=1 768w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Featured-Android_Chips.jpg?resize=640%2C357&amp;ssl=1 640w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Featured-Android_Chips.jpg?resize=600%2C335&amp;ssl=1 600w" sizes="(max-width: 580px) 100vw, 580px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Google&#8217;s material design has been evolving year by year. At first when Material Design was introduced a lot of new components were listed in its documentation. But their implementation or official widgets were not released at that time. But&nbsp;with every support library release, few new significant components are released. With this year&#8217;s Google I/O, Androidx was released as a new implementation for Android&#8217;s support library framework, along with this a new material design component library was also released. As I mentioned above a few new components were released this year too, one of them is Android Chip. This new Android chips widget is now a part of design support library v28 and has also been introduced in this new material design component library 1.0.0. This library has many components but in this article we will be discussing on Android chips only and how to make an Android chips example, via the new <a href="https://material.io/develop/android/docs/getting-started/" target="_blank" rel="noopener noreferrer">Material Component library</a>.</p>



<p class="wp-block-paragraph">Android Pill button or chips have always been a part of our apps. One way or the other building a button like a pill has never been a difficult task for us. But now that Google has&nbsp;officially released a widget by the name of <a href="https://developer.android.com/reference/com/google/android/material/chip/Chip" target="_blank" rel="noopener noreferrer">Chips</a>, it will definitely make our lives easier to some level. In this Android chips example we would learn how to make an android chip button which looks like a pill shaped interact-able element. Please note: To make use of this example, you might have to switch over to&nbsp;<code>AndroidX</code>&nbsp;and&nbsp;<code>com.google.android.material</code>&nbsp;packages by refactoring from the Refactor menu of the Android Studio, as the new material library does not work with old support packages. If you wish to use old support libraries for the time being, please use the v28 of it. It has the Chip widget.</p>



<h2 class="wp-block-heading">Exploring Material Design : Android Chips Example</h2>



<p class="wp-block-paragraph">Generally Android chips are used to capture user input, filter content, trigger actions and simply to make a selection from a choice of options. It should not be used in a situation where a single call to action has to be performed. One of the most obvious example of Android Chips, that you must have seen, should be the Gmail app. In Gmail app when an email address is entered, it is shown in an Android Chip like view. If you wish to make a UI element which looks like the gmail email address pill button type view, you should use the Android Chip widget. To start with the implementation part, first you would have to include the following dependency in your gradle file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">dependencies { 
implementation 'com.google.android.material:material:1.0.0' 
}</pre>



<p class="wp-block-paragraph"><span style="color: #23282d; font-family: Roboto; font-size: 1.4em; font-weight: inherit;">Using Android Chips with Styles</span></p>



<p class="wp-block-paragraph">In simple terms Android Chip is just a combined object of text, icon and optional close icon. With this, the new material design component also gives us a few new attributes to change its appearance and behavior. It allows us to make it&nbsp;represent an attribute, text, entity, or perform an action. This eventually allows the user to trigger an action, filter content, select a choice, or enter information. Also if you have to represent a contact with image, this Android chip can be of good use. To have a more detailed look at the chips, lets have a look at its styles.</p>



<h4 class="wp-block-heading">Action Chip (Default)</h4>



<p class="wp-block-paragraph">The most basic chip of all the available ones is the Action chip. Its a single actionable chip, in short its an alternative to the button widget. If you have to perform an action, based on users tap, this is the chip that you should use. Generally this type of chip is placed after the content of the page and is used as a clickable, just like a button. Have a look at the images below to understand its usage.</p>



<ul data-carousel-extra='{&quot;blog_id&quot;:1,&quot;permalink&quot;:&quot;https://www.truiton.com/2018/10/android-chips-example-material-design/&quot;}'  class="wp-block-gallery columns-2 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex"><li class="blocks-gallery-item"><figure><a href="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-1.jpg?ssl=1"><img data-recalc-dims="1" decoding="async" width="426" height="213" data-attachment-id="2184" data-permalink="https://www.truiton.com/2018/10/android-chips-example-material-design/android-chips-example-1/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-1.jpg?fit=426%2C213&amp;ssl=1" data-orig-size="426,213" data-comments-opened="1" data-image-title="Android chips example -1" data-image-description="" data-image-caption="&lt;p&gt;Android Action Chip Example 1&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-1.jpg?fit=426%2C213&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-1.jpg?resize=426%2C213&#038;ssl=1" alt="Android chips example -1" data-id="2184" class="wp-image-2184" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-1.jpg?w=426&amp;ssl=1 426w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-1.jpg?resize=300%2C150&amp;ssl=1 300w" sizes="(max-width: 426px) 100vw, 426px" /></a></figure></li><li class="blocks-gallery-item"><figure><a href="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-2.jpg?ssl=1"><img data-recalc-dims="1" decoding="async" width="426" height="213" data-attachment-id="2185" data-permalink="https://www.truiton.com/2018/10/android-chips-example-material-design/android-chips-example-2/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-2.jpg?fit=426%2C213&amp;ssl=1" data-orig-size="426,213" data-comments-opened="1" data-image-title="Android chips example -2" data-image-description="" data-image-caption="&lt;p&gt;Android Action Chip Example 2&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-2.jpg?fit=426%2C213&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-2.jpg?resize=426%2C213&#038;ssl=1" alt="Android chips example -2" data-id="2185" class="wp-image-2185" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-2.jpg?w=426&amp;ssl=1 426w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-2.jpg?resize=300%2C150&amp;ssl=1 300w" sizes="(max-width: 426px) 100vw, 426px" /></a></figure></li></ul>



<p class="wp-block-paragraph">To make a working example of Android action chip, you can either define it in the XML or you can insert it dynamically by Java/Kotlin code. In this Android chips example, we will do so by XML and will use its properties in Java code. Please have a look below:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    &lt;com.google.android.material.chip.Chip
        android:id="@+id/action_chip"
        style="@style/Widget.MaterialComponents.Chip.Action"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/action_chip_txt"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:padding="10dp"
        android:text="Hello World"
        app:chipIcon="@drawable/ic_android_24dp"
        app:iconStartPadding="5dp"/></pre>



<p class="wp-block-paragraph">In the above code, please see that we have defined a style tag <code>style="@style/Widget.MaterialComponents.Chip.Action"</code>. This is used to define the style for action chip, but in case if this is missing, it would still render an Android chip with &#8216;Action&#8217; style. As this is also the default style. Moving ahead, to capture this Android chip&#8217;s click event, we use this piece of code:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">        Chip actionChip = findViewById(R.id.action_chip);
        actionChip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "Clicked action chip");
            }
        });</pre>



<h4 class="wp-block-heading">Entry Chip (Input Chip)</h4>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="666" height="207" data-attachment-id="2193" data-permalink="https://www.truiton.com/2018/10/android-chips-example-material-design/android-chips-example-3/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-3.jpg?fit=666%2C207&amp;ssl=1" data-orig-size="666,207" data-comments-opened="1" data-image-title="Android chips example -3" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-3.jpg?fit=666%2C207&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-3.jpg?resize=666%2C207&#038;ssl=1" alt="Android Chips Example - Entry Chip" class="wp-image-2193" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-3.jpg?w=666&amp;ssl=1 666w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-3.jpg?resize=300%2C93&amp;ssl=1 300w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-3.jpg?resize=640%2C199&amp;ssl=1 640w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-3.jpg?resize=600%2C186&amp;ssl=1 600w" sizes="auto, (max-width: 666px) 100vw, 666px" /></figure></div>



<p class="wp-block-paragraph">Another type of chip is the input one, this chip used display captured user input in a non editable format. Its a very nice way to showcase the user input. One of the most obvious usages of Android Entry chip is shown in the gmail app. Particularly the email input experience- when an email is entered by the user, it is showcased as an entry chip, sort of a pill shaped layout. Now according to the material design this element should be an Android Chip with style as &#8216;Entry&#8217;. This chip can also have a close icon along with a chip icon. Generally this type of chip is contained in a <code><code></code></code><a href="https://developer.android.com/reference/com/google/android/material/chip/ChipGroup" target="_blank" rel="noopener noreferrer">ChipGroup</a>. ChipGoup class is similar to <code><code></code></code><a href="https://developer.android.com/reference/android/widget/RadioGroup" target="_blank" rel="noopener noreferrer">RadioGroup</a> class, as it is used to hold multiple chips. It has the properties to display all the chips in a single line. Have a look at the images below to have a better understanding on how the entry chips would look:</p>



<p class="wp-block-paragraph">In case of Android entry chips, in the XML we will create an empty <code>ChipGroup</code> and add chips programmatically. Lets have a look at the layout.xml of the activity:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    &lt;com.google.android.material.chip.ChipGroup
        android:id="@+id/entry_chip_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/entry_chip_txt">

    &lt;/com.google.android.material.chip.ChipGroup></pre>



<p class="wp-block-paragraph">Now since we will be adding chips dynamically through code, a big challenge would be to maintain style along the chips. As per my understanding to maintain consistent styles there are two ways, either by code we style it and use in a loop. Or we create a standard chip style in XML and use it across. Interestingly Android Chips widget also supports a <code><code></code></code><a href="https://developer.android.com/reference/com/google/android/material/chip/ChipDrawable" target="_blank" rel="noopener noreferrer">ChipDrawable</a> class through which we can create a chip dynamically, and this <code>ChipDrawable</code> object can be created by using an XML resource. Therefore as per the principle I like this way better, have a look at my chip style which I used to inject a chip in <code>ChipGroup</code> :</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;chip
    style="@style/Widget.MaterialComponents.Chip.Entry"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:checkable="false"
    app:chipIcon="@drawable/ic_android_24dp"
    app:iconStartPadding="5dp"/></pre>



<p class="wp-block-paragraph">Next to create an Input Chip dynamically we need to define a method :</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    private Chip getChip(final ChipGroup entryChipGroup, String text) {
        final Chip chip = new Chip(this);
        chip.setChipDrawable(ChipDrawable.createFromResource(this, R.xml.my_chip));
        int paddingDp = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 10,
                getResources().getDisplayMetrics()
        );
        chip.setPadding(paddingDp, paddingDp, paddingDp, paddingDp);
        chip.setText(text);
        chip.setOnCloseIconClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                entryChipGroup.removeView(chip);
            }
        });
        return chip;
    }</pre>



<p class="wp-block-paragraph">And this is how an Android Entry Chip is inserted in the chip group:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">final ChipGroup entryChipGroup = findViewById(R.id.entry_chip_group);
final Chip entryChip = getChip(entryChipGroup, "Hello World");
final Chip entryChip2 = getChip(entryChipGroup, "Test");
entryChipGroup.addView(entryChip);
entryChipGroup.addView(entryChip2);</pre>



<h4 class="wp-block-heading">Filter Chip</h4>



<p class="wp-block-paragraph">These type of chips should be used in situations exactly as its name suggests, i.e. for creating filters. Android filter chips are similar to check boxes, in a way they should be used to filter the content. For example if you have to show a UI where there&#8217;s a list and user has to filter a specific type of content from it, in this situation a filter chip would be an apt solution. Generally filter chips do not have a icon attached to them, as a check icon is displayed once a chip is selected. Please have a look at the images below:</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="462" height="195" data-attachment-id="2196" data-permalink="https://www.truiton.com/2018/10/android-chips-example-material-design/android-chips-example-4/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-4.jpg?fit=462%2C195&amp;ssl=1" data-orig-size="462,195" data-comments-opened="1" data-image-title="Android chips example -4" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-4.jpg?fit=462%2C195&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-4.jpg?resize=462%2C195&#038;ssl=1" alt="Android chips example -4" class="wp-image-2196" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-4.jpg?w=462&amp;ssl=1 462w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-4.jpg?resize=300%2C127&amp;ssl=1 300w" sizes="auto, (max-width: 462px) 100vw, 462px" /></figure></div>



<p class="wp-block-paragraph">Further lets define the XML for Android Filter Chips, they have&nbsp;<code>style="@style/Widget.MaterialComponents.Chip.Filter"</code> :</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    &lt;com.google.android.material.chip.ChipGroup
        android:id="@+id/filter_chip_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/filter_chip_txt">

        &lt;com.google.android.material.chip.Chip
            android:id="@+id/filter_chip"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:text="Dogs"/>

        &lt;com.google.android.material.chip.Chip
            android:id="@+id/filter_chip2"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="Cats"/>
    &lt;/com.google.android.material.chip.ChipGroup></pre>



<p class="wp-block-paragraph">Now that we have filter chips in place, we need to detect clicks on the filter chips. We can do so simply by attaching a OnCheckedChangeListener to it:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">        ChipGroup filterChipGroup = findViewById(R.id.filter_chip_group);
        Chip filterChip = findViewById(R.id.filter_chip);
        Chip filterChip2 = findViewById(R.id.filter_chip2);
        CompoundButton.OnCheckedChangeListener filterChipListener = new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.i(TAG, buttonView.getId() + "");
            }
        };
        filterChip.setOnCheckedChangeListener(filterChipListener);
        filterChip2.setOnCheckedChangeListener(filterChipListener);</pre>



<h4 class="wp-block-heading">Filter Chip &#8211; Single Selection Mode</h4>



<p class="wp-block-paragraph">In this <a href="https://www.truiton.com/2018/10/android-chips-example-material-design/">Android Chips Example</a>, I will also show a filter chip with single selection mode. In this mode, filter chips would start acting as a radio button. This means in a way only one selection can be made at a time. This functionality is achieved by adding all the filter chips in a <code>ChipGroup</code> and setting the property : <code>app:singleSelection="true"</code>&nbsp;of Chip Group. To have a better understanding, lets have a look at the layout XML file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    &lt;com.google.android.material.chip.ChipGroup
        android:id="@+id/filter_chip_SS_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/filter_chip_ss_txt"
        app:singleSelection="true">

        &lt;com.google.android.material.chip.Chip
            android:id="@+id/filter_ss_chip"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:text="Dogs"/>

        &lt;com.google.android.material.chip.Chip
            android:id="@+id/filter_ss_chip2"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="Cats"/>
    &lt;/com.google.android.material.chip.ChipGroup></pre>



<p class="wp-block-paragraph">Next to capture the selected chip out of all chips, we need to attach a&nbsp;<code>ChipGroup.OnCheckedChangeListener()</code> on the <code>ChipGroup</code>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">        ChipGroup filterChipGroupSingleSelection = findViewById(R.id.filter_chip_SS_group);
        filterChipGroupSingleSelection.setOnCheckedChangeListener(new ChipGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(ChipGroup group, @IdRes int checkedId) {
                // Handle the checked chip change.
                Log.i(TAG, "ID: " + group.getCheckedChipId());
            }
        });</pre>



<p class="wp-block-paragraph">Please Note: This <code>ChipGroup.OnCheckedChangeListener()</code> would return callbacks only when single selection mode is set to <code>true</code>.</p>



<h4 class="wp-block-heading">Choice Chip</h4>



<p class="wp-block-paragraph">A perfect example of choice chip is similar to the filter chip one. Choice chip allows the user to select only one of the available options just like the filter chips. But with one difference, it does not have a check icon on it. Instead according to material design guidelines, it displays the selection with a change of color, when it is selected. If you wish you can use a chipIcon with this chip. But ideally they should be used wherever you feel the need to show RadioButton. Lets have a look at the UI for Android Choice Chip:</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="360" height="189" data-attachment-id="2198" data-permalink="https://www.truiton.com/2018/10/android-chips-example-material-design/android-chips-example-5/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-5.jpg?fit=360%2C189&amp;ssl=1" data-orig-size="360,189" data-comments-opened="1" data-image-title="Android chips example -5" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-5.jpg?fit=360%2C189&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-5.jpg?resize=360%2C189&#038;ssl=1" alt="Android chips example -5" class="wp-image-2198" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-5.jpg?w=360&amp;ssl=1 360w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2018/10/Android-chips-example-5.jpg?resize=300%2C158&amp;ssl=1 300w" sizes="auto, (max-width: 360px) 100vw, 360px" /></figure></div>



<p class="wp-block-paragraph">To use the choice chip, we use&nbsp;<code>style="@style/Widget.MaterialComponents.Chip.Choice"</code> parameter in the XML. Lets have a look at the XML:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    &lt;com.google.android.material.chip.ChipGroup
        android:id="@+id/choice_chip_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/choice_chip_txt"
        app:singleSelection="true">

        &lt;com.google.android.material.chip.Chip
            android:id="@+id/choice_chip"
            style="@style/Widget.MaterialComponents.Chip.Choice"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:text="Cars"/>

        &lt;com.google.android.material.chip.Chip
            android:id="@+id/choice_chip2"
            style="@style/Widget.MaterialComponents.Chip.Choice"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="Trucks"/>
    &lt;/com.google.android.material.chip.ChipGroup></pre>



<p class="wp-block-paragraph">As shown in this Android Chips Example earlier, ChipGroup can return the selected chip only when single selection mode is set to true. Even here we will utilize the same property and capture the selection:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">        ChipGroup choiceChipGroup = findViewById(R.id.choice_chip_group);
        choiceChipGroup.setOnCheckedChangeListener(new ChipGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(ChipGroup chipGroup, @IdRes int i) {
                Log.i(TAG, i + "");
            }
        });</pre>



<p class="wp-block-paragraph">If you wish to have a look at all the working sample of the Android Chip types mentioned above, please have a look at the full source code here:&nbsp;</p>



<p class="wp-block-paragraph" style="text-align:center"><a class="fasc-button fasc-size-large fasc-type-flat fasc-rounded-medium ico-fa fasc-ico-before fa-github" style="background-color: #0364af; color: #ffffff;" target="_blank" rel="noopener noreferrer" href="https://github.com/Truiton/ChipsExample">Full Source Code</a>&nbsp;</p>



<p class="wp-block-paragraph">In this Android Chips Example, as you can see we built a working sample of all the chip styles, by using the latest Google&#8217;s material library. Here in this tutorial we also showcased, that a chip has the properties of a radio button as well as a check box. In a way its a better representation of both.&nbsp;You can use it either in a single selection or in multiple selection mode. Both ways it would give a great experience.&nbsp;As the Android Chips are compact, relevant and focused. Hope this example made you understand things better, for latest news on Android connect with us on Twitter, Facebook and Google+. Also subscribe to our newsletter, for news right in your inbox.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2018/10/android-chips-example-material-design/">Android Chips Example: Material Design</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2018/10/android-chips-example-material-design/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2119</post-id>	</item>
		<item>
		<title>Android Bottom Sheet Example</title>
		<link>https://www.truiton.com/2016/07/android-bottom-sheet-example/</link>
					<comments>https://www.truiton.com/2016/07/android-bottom-sheet-example/#comments</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Sun, 17 Jul 2016 17:22:29 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Material Design]]></category>
		<category><![CDATA[Material Design Backward Compatibility]]></category>
		<guid isPermaLink="false">http://www.truiton.com/?p=1535</guid>

					<description><![CDATA[<p>When in 2014, Google introduced Material Design, they introduced many new design components, like Floating Action button, Tabs, Cards, and Bottom Sheets for Android. Although most of the new components were not available&#160;for&#160;Android&#160;at that moment. But over time they released a support library by the name of Design Support Library. Which thankfully helped the developers&#160;to&#8230;&#160;<a href="https://www.truiton.com/2016/07/android-bottom-sheet-example/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Android Bottom Sheet Example</span></a></p>
<p>The post <a href="https://www.truiton.com/2016/07/android-bottom-sheet-example/">Android Bottom Sheet Example</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="950" height="530" data-attachment-id="1536" data-permalink="https://www.truiton.com/2016/07/android-bottom-sheet-example/android-bottom-sheet-featured/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Featured.jpg?fit=950%2C530&amp;ssl=1" data-orig-size="950,530" data-comments-opened="1" data-image-title="Android Bottom Sheet &amp;#8211; Featured" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Featured.jpg?fit=950%2C530&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Featured.jpg?resize=950%2C530" alt="Android Bottom Sheet - Featured" class="wp-image-1536" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Featured.jpg?w=950&amp;ssl=1 950w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Featured.jpg?resize=600%2C335&amp;ssl=1 600w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Featured.jpg?resize=300%2C167&amp;ssl=1 300w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Featured.jpg?resize=768%2C428&amp;ssl=1 768w" sizes="auto, (max-width: 950px) 100vw, 950px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">When in 2014, Google introduced <a href="https://material.google.com/" target="_blank" rel="noopener noreferrer">Material Design</a>, they introduced many new design components, like <a href="http://www.truiton.com/2015/04/floating-action-buttons-android/" target="_blank" rel="noopener noreferrer">Floating Action button</a>, <a href="http://www.truiton.com/2015/06/android-tabs-example-fragments-viewpager/" target="_blank" rel="noopener noreferrer">Tabs</a>, <a href="http://www.truiton.com/2015/03/android-cardview-example/" target="_blank" rel="noopener noreferrer">Cards</a>, and <a href="https://material.google.com/components/bottom-sheets.html" target="_blank" rel="noopener noreferrer">Bottom Sheets</a> for Android. Although most of the new components were not available&nbsp;for&nbsp;Android&nbsp;at that moment. But over time they released a support library by the name of <a href="http://android-developers.blogspot.in/2015/05/android-design-support-library.html" target="_blank" rel="noopener noreferrer">Design Support Library</a>. Which thankfully helped the developers&nbsp;to utilize the power of material design on Android. Recently a new design component was introduced in this support library called the Bottom Sheet. Here in this Android Bottom Sheet example, we would make a short example using the new component to understand its working.&nbsp;But first lets understand what is an Android Bottom Sheet.</p>



<p class="wp-block-paragraph">According to material design, <a href="https://material.google.com/components/bottom-sheets.html" target="_blank" rel="noopener noreferrer">Bottom Sheets</a> can be of two types: <strong>Persistent</strong> and <strong>Modal</strong>. Here in this example we would make samples for both types of Android Bottom sheets. As per documentation persistent bottom sheets are supposed to be in-app content.&nbsp;Hence they are included right inside the main layout. In a way they are supposed to be integrated with the app or screen. On the other hand Modal Bottom sheets are a little different; they are supposed to be used as the layer on top of your app. Mostly they are inferred as an external entity, like a menu. Also since they are like menus, therefore&nbsp;if they are visible to the user, they do not allow the user to interact with main screen in background. First they need to dismiss&nbsp;the Android Bottom Sheet,&nbsp;only then the user would be allowed to interact with main activity. Lets learn more about them in the next sections, also full source code is available for this example at the bottom of this write-up. But first,&nbsp;lets&nbsp;please include these dependencies in our&nbsp;build.gradle file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
}</pre>



<h2 class="wp-block-heading">Android Bottom Sheet : Persistent</h2>



<p class="wp-block-paragraph">To make some content beautifully slide in and out of a screen, we can use the persistent Bottom Sheets on Android.&nbsp;To make a view as persistent Bottom Sheet in your screen all you need to do is have <code>CoordinatorLayout</code> at the top level of your layout. Next a behavior&nbsp;should be specified in the layout you need to make a Bottom Sheet. To understand better lets define the layout:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?xml version="1.0" encoding="utf-8"?>
&lt;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="com.truiton.bottomsheet_persistent.MainActivity">

    &lt;android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        &lt;RelativeLayout
            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">

            &lt;ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:src="@mipmap/truiton"/>

            &lt;Button
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/image"
                android:layout_centerHorizontal="true"
                android:text="Show Bottom Sheet"/>
        &lt;/RelativeLayout>
    &lt;/android.support.v4.widget.NestedScrollView>

    &lt;RelativeLayout
        android:id="@+id/design_bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        app:behavior_hideable="true"
        app:behavior_peekHeight="50dp"
        app:elevation="4dp"
        app:layout_behavior="@string/bottom_sheet_behavior">

        &lt;TextView
            android:id="@+id/bottomsheet_text"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="Introducing Bottom Sheets"
            android:textColor="#FFFFFF"/>

    &lt;/RelativeLayout>


&lt;/android.support.design.widget.CoordinatorLayout>
</pre>



<p class="wp-block-paragraph">This would result in a screen with Android Bottom sheet like this:</p>



<ul data-carousel-extra='{&quot;blog_id&quot;:1,&quot;permalink&quot;:&quot;https://www.truiton.com/2016/07/android-bottom-sheet-example/&quot;}'  class="wp-block-gallery columns-3 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex"><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="500" height="893" data-attachment-id="1539" data-permalink="https://www.truiton.com/2016/07/android-bottom-sheet-example/android-bottom-sheet-persistent-1/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-1.png?fit=500%2C893&amp;ssl=1" data-orig-size="500,893" data-comments-opened="1" data-image-title="Android Bottom Sheet Persistent -1" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-1.png?fit=500%2C893&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-1.png?resize=500%2C893&#038;ssl=1" alt="Android Bottom Sheet Persistent -1" data-id="1539" class="wp-image-1539" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-1.png?w=500&amp;ssl=1 500w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-1.png?resize=168%2C300&amp;ssl=1 168w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-1.png?resize=300%2C536&amp;ssl=1 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /></figure></li><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="500" height="893" data-attachment-id="1540" data-permalink="https://www.truiton.com/2016/07/android-bottom-sheet-example/android-bottom-sheet-persistent-2/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-2.png?fit=500%2C893&amp;ssl=1" data-orig-size="500,893" data-comments-opened="1" data-image-title="Android Bottom Sheet Persistent -2" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-2.png?fit=500%2C893&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-2.png?resize=500%2C893&#038;ssl=1" alt="Android Bottom Sheet Persistent -2" data-id="1540" class="wp-image-1540" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-2.png?w=500&amp;ssl=1 500w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-2.png?resize=168%2C300&amp;ssl=1 168w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Persistent-2.png?resize=300%2C536&amp;ssl=1 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /></figure></li></ul>



<p class="wp-block-paragraph">One of the great parts about persistent Bottom Sheets is that, they can be dragged to go full screen, even if they don&#8217;t have the content for a full page. On the other hand Modal Bottom Sheets does not allow this.</p>



<p class="wp-block-paragraph">Also if you closely observe&nbsp;the Android bottom sheet shown above, you may see that it stays below the Action bar. If you wish to make it go over the action bar. Please change the activity theme to <code>Theme.AppCompat.Light.NoActionBar</code> and add the elevation of&nbsp;<code>4dp</code>&nbsp;in Bottom Sheet. It would start sliding right over the Toolbar (if added). Next lets have a look at the java file for this screen.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">package com.truiton.bottomsheet_persistent;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        View bottomSheet = findViewById(R.id.design_bottom_sheet);
        final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
        behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                switch (newState) {
                    case BottomSheetBehavior.STATE_DRAGGING:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_DRAGGING");
                        break;
                    case BottomSheetBehavior.STATE_SETTLING:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_SETTLING");
                        break;
                    case BottomSheetBehavior.STATE_EXPANDED:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_EXPANDED");
                        break;
                    case BottomSheetBehavior.STATE_COLLAPSED:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_COLLAPSED");
                        break;
                    case BottomSheetBehavior.STATE_HIDDEN:
                        Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_HIDDEN");
                        break;
                }
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                Log.i("BottomSheetCallback", "slideOffset: " + slideOffset);
            }
        });

        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (behavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
                    behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                } else {
                    behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                }
            }
        });
    }
}
</pre>



<p class="wp-block-paragraph">In the above piece of code, you may see that I have added a <code>BottomSheetBehavior</code> callback interface, to listen to the changes in Bottom Sheet states. Although in the above code its not serving any purpose, but its added for reference. Full source code is available here:</p>



<p class="wp-block-paragraph" style="text-align:center"><a class="fasc-button fasc-size-large fasc-type-flat fasc-rounded-medium ico-fa fasc-ico-before fa-github" style="background-color: #0364af; color: #ffffff;" target="_blank" rel="noopener noreferrer" href="https://github.com/Truiton/BottomSheetBehavior">Source Code</a></p>



<h2 class="wp-block-heading">Android Bottom Sheet :&nbsp;Modal</h2>



<p class="wp-block-paragraph">Second&nbsp;type of Bottom Sheet is the modal sheet. According to the documentation this component should act as a menu or&nbsp;a sheet which does not allow the users to interact with main screen until it&nbsp;is dismissed.&nbsp;Surprisingly when speaking of Android, this design pattern&nbsp;is similar to a dialog box. Hence a new class <code>BottomSheetDialogFragment</code> was introduced; extending the <code>AppCompatDialogFragment</code>. Which resulted in a perfect modal type Android Bottom Sheet.</p>



<p class="wp-block-paragraph">Now technically speaking; when we talk of modal type Android bottom sheets, we have to create an XML outside of the activity separately to inflate in the&nbsp;<code>BottomSheetDialogFragment.</code> To start off lets have a look at the XMLs first:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?xml version="1.0" encoding="utf-8"?>
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@color/colorAccent"
              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">

    &lt;TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Introducing Modal Bottom Sheet"
        android:textColor="#FFFFFF"/>

    &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
        android:textColor="#FFFFFF"/>

    &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
        android:textColor="#FFFFFF"/>

&lt;/LinearLayout></pre>



<p class="wp-block-paragraph">Also have a look at the XML for MainActivity:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?xml version="1.0" encoding="utf-8"?>
&lt;RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    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.truiton.bottomsheet_modal.MainActivity">

    &lt;ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@mipmap/truiton"/>

    &lt;Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/image"
        android:layout_centerHorizontal="true"
        android:text="Show Modal Bottom Sheet"/>
&lt;/RelativeLayout>
</pre>



<p class="wp-block-paragraph">Now that we have XMLs in place. Lets have a look at some code for the MainActivity:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">package com.truiton.bottomsheet_modal;

import android.os.Bundle;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final BottomSheetDialogFragment myBottomSheet = MyBottomSheetDialogFragment.newInstance("Modal Bottom Sheet");

        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                myBottomSheet.show(getSupportFragmentManager(), myBottomSheet.getTag());
            }
        });
    }
}
</pre>



<p class="wp-block-paragraph">Over here you may see that, to actually show a&nbsp;Bottom Sheet&nbsp;we&nbsp;are using an instance of the&nbsp;<code>BottomSheetDialogFragment</code>. Therefore lets have a look at the class for bottom sheet.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">package com.truiton.bottomsheet_modal;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created by MG on 17-07-2016.
 */
public class MyBottomSheetDialogFragment extends BottomSheetDialogFragment {

    String mString;

    static MyBottomSheetDialogFragment newInstance(String string) {
        MyBottomSheetDialogFragment f = new MyBottomSheetDialogFragment();
        Bundle args = new Bundle();
        args.putString("string", string);
        f.setArguments(args);
        return f;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mString = getArguments().getString("string");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.bottom_sheet_modal, container, false);
        TextView tv = (TextView) v.findViewById(R.id.text);
        return v;
    }
}
</pre>



<p class="wp-block-paragraph">As you can see, the working of above class is just like any <code>DialogFragment</code> in Android. Hence&nbsp;we inflated the layout in <code>onCreateView()</code> method, which made the Bottom Sheet to look like:</p>



<ul data-carousel-extra='{&quot;blog_id&quot;:1,&quot;permalink&quot;:&quot;https://www.truiton.com/2016/07/android-bottom-sheet-example/&quot;}'  class="wp-block-gallery columns-3 is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex"><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="500" height="893" data-attachment-id="1543" data-permalink="https://www.truiton.com/2016/07/android-bottom-sheet-example/android-bottom-sheet-modal-2/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-2.png?fit=500%2C893&amp;ssl=1" data-orig-size="500,893" data-comments-opened="1" data-image-title="Android Bottom Sheet Modal -2" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-2.png?fit=500%2C893&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-2.png?resize=500%2C893&#038;ssl=1" alt="Android Bottom Sheet Modal -2" data-id="1543" class="wp-image-1543" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-2.png?w=500&amp;ssl=1 500w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-2.png?resize=168%2C300&amp;ssl=1 168w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-2.png?resize=300%2C536&amp;ssl=1 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /></figure></li><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="500" height="893" data-attachment-id="1544" data-permalink="https://www.truiton.com/2016/07/android-bottom-sheet-example/android-bottom-sheet-modal-1/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-1.png?fit=500%2C893&amp;ssl=1" data-orig-size="500,893" data-comments-opened="1" data-image-title="Android Bottom Sheet Modal -1" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-1.png?fit=500%2C893&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-1.png?resize=500%2C893&#038;ssl=1" alt="Android Bottom Sheet Modal -1" data-id="1544" class="wp-image-1544" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-1.png?w=500&amp;ssl=1 500w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-1.png?resize=168%2C300&amp;ssl=1 168w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2016/07/Android-Bottom-Sheet-Modal-1.png?resize=300%2C536&amp;ssl=1 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /></figure></li></ul>



<p class="wp-block-paragraph">Another interesting thing about the modal type android bottom sheets is that, they render themselves on top of the view hierarchy making the background a little dull. Also this type of Bottom sheet automatically covers the action bar or toolbar, as its on top of the view hierarchy. Another thing that distinguishes between the modal and persistent Bottom sheets is that; modal sheets expand until the content is visible, once whole content is visible they don&#8217;t expand any further. Unlike the persistent type Android bottom sheet which cover the screen regardless of content. To view the full source code, please refer to the link below:</p>



<p class="wp-block-paragraph" style="text-align:center"><a class="fasc-button fasc-size-large fasc-type-flat fasc-rounded-medium ico-fa fasc-ico-before fa-github" style="background-color: #0364af; color: #ffffff;" target="_blank" rel="noopener noreferrer" href="https://github.com/Truiton/BottomSheetBehavior">Source Code</a></p>



<p class="wp-block-paragraph">Many apps are starting to use this component; as it has the inbuilt sliding feature, which&nbsp;adds on to a&nbsp;good user experience. In a way the new <a href="http://www.truiton.com/2016/07/android-bottom-sheet-example/">bottom sheet design component</a> could turn out to be very useful in an Android app. As it gives a new hidden space within the screen, which the user can relate to and slide out at any time. Also&nbsp;since now it has been fully integrated in to the Android platform, I recommend all of the apps should use this component to make apps more interactive and more connected to the user. Hope this helps, connect with us on Twitter, Facebook and Google+ for more updates.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2016/07/android-bottom-sheet-example/">Android Bottom Sheet Example</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2016/07/android-bottom-sheet-example/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1535</post-id>	</item>
		<item>
		<title>Android Material Design Buttons &#8211; Best Approach</title>
		<link>https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/</link>
					<comments>https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/#comments</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Thu, 09 Apr 2015 12:38:54 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Material Design]]></category>
		<category><![CDATA[Material Design Backward Compatibility]]></category>
		<guid isPermaLink="false">http://www.truiton.com/?p=1065</guid>

					<description><![CDATA[<p>One of the most basic design component in any Android app is a button. Google released a new design pattern lately by the name of Material Design. With material design, Google released new standards for buttons. These buttons have a unique feature that they show a ripple when touched. When speaking of Android material design&#8230;&#160;<a href="https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Android Material Design Buttons &#8211; Best Approach</span></a></p>
<p>The post <a href="https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/">Android Material Design Buttons &#8211; Best Approach</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="950" height="534" data-attachment-id="1066" data-permalink="https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/android-material-design-button-featured/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button-Featured.jpg?fit=950%2C534&amp;ssl=1" data-orig-size="950,534" data-comments-opened="1" data-image-title="Android Material Design Button &amp;#8211; Featured" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button-Featured.jpg?fit=950%2C534&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button-Featured.jpg?resize=950%2C534" alt="Android Material Design Button" class="wp-image-1066" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button-Featured.jpg?w=950&amp;ssl=1 950w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button-Featured.jpg?resize=300%2C169&amp;ssl=1 300w" sizes="auto, (max-width: 950px) 100vw, 950px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">One of the most basic design component in any Android app is a button. Google released a new design pattern lately by the name of <a href="http://www.google.co.in/design/spec/material-design/introduction.html" target="_blank" rel="noopener noreferrer">Material Design</a>. With material design, Google released new standards for buttons. These buttons have a unique feature that they show a ripple when touched. When speaking of Android material design buttons, they are broadly categorized into four types:</p>



<ol class="wp-block-list"><li>Raised Button &#8211; A normal button</li><li>Flat Button &#8211; A button for cards, toolbars and dialogs</li><li><a title="Floating Action Buttons In Android" href="http://www.truiton.com/2015/04/floating-action-buttons-android/" target="_blank" rel="noopener noreferrer">Floating Button</a> &#8211; A hovering button for most important or promoted action</li><li>Other Buttons &#8211; Icons, drop downs etc.</li></ol>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Here we will discuss how to make raised and flat buttons according to the material design specifications for Android, with full backward support. Google has very clearly defined, how a material design button should look and feel when touched. But one of the most basic problem still prevails. How should a button look in the earlier versions of Android?</p>



<p class="wp-block-paragraph">As of now, if you create a normal button with <code>Button</code> xml tag, it would look like a material design button in Android 5.0 and above. But before that it would look, as it should on the respective version. Another point that I would like to make is here is that, with android support v7 AppCompat library, you can support material theme to an extent. But sadly even with support library, as of now you may not be able to show Android material design buttons on all versions of android.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">Android Material Design Raised Button</h2>



<h3 class="wp-block-heading">1) Standard Button</h3>



<p class="wp-block-paragraph">Use the code below to make a raised button:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    &lt;Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:text="Normal Button"/></pre>



<p class="wp-block-paragraph">First button in the screenshot below shows this button.</p>



<h3 class="wp-block-heading">2) Material design raised button with CardView</h3>



<p class="wp-block-paragraph">If you want to make a button, which looks like the material design button, with backward support. Try using the CardView library for it. Have a look at the code below:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    &lt;android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="wrap_content"
        android:layout_height="36dp"
        android:layout_below="@+id/button2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        card_view:cardBackgroundColor="#d9d9d9"
        card_view:cardCornerRadius="2dp"
        card_view:cardElevation="1dp">

        &lt;RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            &lt;TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:gravity="center"
                android:minWidth="88dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:singleLine="true"
                android:text="CARDVIEW BUTTON"
                android:textColor="#000000"/>
        &lt;/RelativeLayout>
    &lt;/android.support.v7.widget.CardView></pre>



<p class="wp-block-paragraph">The above piece of code would make a raised button according to the Android material design guideline, with support from API 11 and above. If you closely notice I have used the&nbsp;<code>"?android:attr/selectableItemBackground"</code> property to show ripples on this view. This property can make any view to show ripples, if they detect touch events. Also please don&#8217;t forget to make CardView clickable by adding&nbsp;<code>android:clickable="true"</code> property as shown above. This button would look exactly the same across all supported devices. Learn more about <a title="Android CardView Example" href="http://www.truiton.com/2015/03/android-cardview-example/" target="_blank" rel="noopener noreferrer">CardView here</a>. Have a look in the screen shot below, its the third button:</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="500" height="805" data-attachment-id="1069" data-permalink="https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/android-material-design-button/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button.png?fit=500%2C805&amp;ssl=1" data-orig-size="500,805" data-comments-opened="1" data-image-title="Android Material Design Button" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button.png?fit=500%2C805&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button.png?resize=500%2C805" alt="Android Material Design Button" class="wp-image-1069" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button.png?w=500&amp;ssl=1 500w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button.png?resize=186%2C300&amp;ssl=1 186w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button.png?resize=300%2C483&amp;ssl=1 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">You can attach an OnClickListener to this button and make it work just like a normal button:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">        CardView cv = (CardView)findViewById(R.id.card_view);
        cv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("Activity", "Clicked");
            }
        });</pre>



<p class="wp-block-paragraph">Although the ripple effect would show only in 5.0 and above devices as even CardView or any other view does not support it on earlier versions. On <span style="text-decoration: underline;">earlier versions of Android</span>, this is how the selection would appear:</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="276" height="98" data-attachment-id="1070" data-permalink="https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/android-material-design-button-cardview/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button-CardView.png?fit=276%2C98&amp;ssl=1" data-orig-size="276,98" data-comments-opened="1" data-image-title="Android Material Design Button &amp;#8211; CardView" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button-CardView.png?fit=276%2C98&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Material-Design-Button-CardView.png?resize=276%2C98" alt="Android Material Design Button - CardView" class="wp-image-1070"/></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">But the button would still appear like a card, as expected. Therefore the above piece of code would make an Android material design button with backward support but with some limitations. Unfortunately there is no support from Google on it right now. Also in some of their posts they have mentioned, that ripple effect is not added in support library as it degrades performance. Just a personal thought: maybe in future, they might start supporting ripples too.</p>



<h2 class="wp-block-heading">Android Material Design Flat Button</h2>



<p class="wp-block-paragraph">Another type of button is flat button. These type of buttons are used to avoid gratuitous layering. For example it is suggested to use this type of button on a CardView, instead of normal raised button. The main purpose of this button is to minimize the user distraction from content. To make a button flat button just add <code>style="?android:attr/borderlessButtonStyle"</code> in your button layout. Just like the code below:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    &lt;Button
        android:id="@+id/button2"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Borderless Button"/></pre>



<p class="wp-block-paragraph">This button is shown at number 2 in the screen shot above.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">Although android material design buttons are not fully supported by all the versions till now. Still I would say that they add, great value to the style quotient of your app. They give a neat and clean look to your app. Hence I would suggest to use them with all the backward support available. Also I have not mentioned here, a lot of open-source libraries are also available which, endorse material design buttons. Hope this helped, please connect with us on Facebook, Google+ and Twitter for more updates.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/">Android Material Design Buttons &#8211; Best Approach</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2015/04/android-material-design-buttons-best-approach/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1065</post-id>	</item>
		<item>
		<title>Floating Action Buttons In Android</title>
		<link>https://www.truiton.com/2015/04/floating-action-buttons-android/</link>
					<comments>https://www.truiton.com/2015/04/floating-action-buttons-android/#comments</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Tue, 07 Apr 2015 17:34:02 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Material Design]]></category>
		<category><![CDATA[Material Design Backward Compatibility]]></category>
		<guid isPermaLink="false">http://www.truiton.com/?p=1044</guid>

					<description><![CDATA[<p>Even though I am an Android developer, sometimes I feel, a lot of new concepts in Android are released in a jiffy. Take for an example, Android material design. It greatly emphasizes on the usage of Floating Action Buttons. But as a matter of fact, when material design was released; no supporting views were released&#8230;&#160;<a href="https://www.truiton.com/2015/04/floating-action-buttons-android/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Floating Action Buttons In Android</span></a></p>
<p>The post <a href="https://www.truiton.com/2015/04/floating-action-buttons-android/">Floating Action Buttons In Android</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="950" height="534" data-attachment-id="1048" data-permalink="https://www.truiton.com/2015/04/floating-action-buttons-android/android-floating-action-button/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Floating-Action-Button.jpg?fit=950%2C534&amp;ssl=1" data-orig-size="950,534" data-comments-opened="1" data-image-title="Android Floating Action Button" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Floating-Action-Button.jpg?fit=950%2C534&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Floating-Action-Button.jpg?resize=950%2C534" alt="Android Floating Action Button" class="wp-image-1048" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Floating-Action-Button.jpg?w=950&amp;ssl=1 950w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-Floating-Action-Button.jpg?resize=300%2C169&amp;ssl=1 300w" sizes="auto, (max-width: 950px) 100vw, 950px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Even though I am an Android developer, sometimes I feel, a lot of new concepts in Android are released in a jiffy. Take for an example, Android material design. It greatly emphasizes on the usage of <a title="Android Material Design Buttons" href="http://www.google.co.in/design/spec/components/buttons.html" target="_blank" rel="noopener noreferrer">Floating Action Buttons</a>. But as a matter of fact, when material design was released; no supporting views were released with it, to display a floating action button in android. Although they did provide a <a title="Android Floating Action Button Sample" href="https://developer.android.com/samples/FloatingActionButtonBasic/index.html" target="_blank" rel="noopener noreferrer">sample here</a>, but it had a limitation that it can be used on API 21 and above only. In a way it is correct, that it should not be used on earlier versions of Android. Since material design guidelines came with API 21. But on the other hand the AppCompat support library v7 makes makes most of the <a title="Android Material Design With Backward Compatibility" href="http://www.truiton.com/2015/02/android-material-design-backward-compatibility/" target="_blank" rel="noopener noreferrer">material design compatible</a> with earlier versions of Android. Therefore, when we use the Android floating action button, we are bound to display it on all versions of android which are supported by our app.</p>



<p class="wp-block-paragraph">This brings up a fresh debate on how to display a floating action button in an android app, with backward support. Thanks&nbsp; to recent developments a new addition in the support repository has been made which enables us to show FAB in Android. It is called Android Design Support Library. But since this addition came in almost a year late, many third party libraries are also available, through which a FAB can be implemented. In this tutorial, we will talk about some of the leading Android FAB libraries:</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">Android Floating Action Buttons Tutorial</h2>



<p class="wp-block-paragraph">I will use a RecyclerView, on top of which I will be displaying an Android FAB button. Further in this tutorial I will use that FAB button to add an item in my RecyclerView. To ease the development I will refer to my <a title="Android RecyclerView Tutorial" href="http://www.truiton.com/2015/02/android-recyclerview-tutorial/" target="_blank" rel="noopener noreferrer">RecyclerView tutorial</a>, which already has a defined method for adding an item in the RecyclerView.</p>



<h3 class="wp-block-heading">1) <a href="http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html" target="_blank" rel="noopener noreferrer">FloatingActionButton</a> by Official Android <a href="http://developer.android.com/tools/support-library/features.html#design" target="_blank" rel="noopener noreferrer">Design Support Library</a></h3>



<p class="wp-block-paragraph">As I mentioned recently in the start of June 15, a new library was added in the Android support repository, called the Design Support library. This library has many new UI widgets, but one of the most important addition is the <code><code></code></code><a href="http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html">FloatingActionButton</a>. Now android supports the Floating action button from API 7 and above through the official support library. To start please include the new Android design support library in your project&#8217;s build.gradle file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">compile 'com.android.support:design:22.2.0'</pre>



<p class="wp-block-paragraph">Next to display the Android Floating Action Button, please use the <code>android.support.design.widget.FloatingActionButton</code> xml tag to include it in your layout:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;android.support.design.widget.CoordinatorLayout
    android:id="@+id/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=".FABActivity">

    &lt;RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        &lt;android.support.v7.widget.RecyclerView
            android:id="@+id/my_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"/>

    &lt;/RelativeLayout>

    &lt;android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        android:src="@mipmap/ic_add"
        app:fabSize="normal"
        app:layout_anchor="@id/coordinatorLayout"
        app:layout_anchorGravity="bottom|right|end"
        app:rippleColor="#F06292"/>
&lt;/android.support.design.widget.CoordinatorLayout>
</pre>



<p class="wp-block-paragraph">You may observe that I am also using a <a href="http://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.html" target="_blank" rel="noopener noreferrer">CoordinatorLayout</a> with this floating action button. Coordinator Layout helps us in building interactions between child views. Although in this example there is no use for a coordinator layout, but it can help if a snackbar is used. To read more about it please refer to this <a href="http://www.truiton.com/2015/06/android-snackbar-example/" target="_blank" rel="noopener noreferrer">Android Snackbar Tutorial</a>.</p>



<p class="wp-block-paragraph">To detect clicks from an Android Floating Action Button please use this piece of code:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //Write here anything that you wish to do on click of FAB
        // Code to Add an item with default animation
        int index = mAdapter.getItemCount();
        DataObject obj = new DataObject("Some Primary Text " + index,
                "Secondary " + index);
        ((MyRecyclerViewAdapter) mAdapter).addItem(obj, index);
        //Ends Here
    }
});</pre>



<h3 class="wp-block-heading">2) <a href="https://github.com/makovkastar/FloatingActionButton" target="_blank" rel="noopener noreferrer">FloatingActionButton</a> by <a href="https://github.com/makovkastar" target="_blank" rel="noopener noreferrer">makovkastar</a></h3>



<p class="wp-block-paragraph">This library is one of the most popular floating action button libraries available. Most of the apps are using this library. Its quite simple to use as well. It offers a great feature of showing and hiding the FAB with animation, which can give a wow factor to your app. It works for Android API 7 and above, and has an Apache 2.0 license. To start off, please include it in the dependencies section of your gradle file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">compile 'com.melnykov:floatingactionbutton:1.3.0'</pre>



<p class="wp-block-paragraph">Further, please add&nbsp;<code>com.melnykov.fab.FloatingActionButton</code> view to your layout for displaying an Android FAB with RecyclerView:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                xmlns:fab="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".FABActivity">

    &lt;android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"/>

    &lt;com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:src="@mipmap/ic_add"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        fab:fab_colorNormal="#FF4081"
        fab:fab_colorPressed="#C2185B"
        fab:fab_colorRipple="#F06292"/>

&lt;/RelativeLayout>
</pre>



<p class="wp-block-paragraph">In the above layout I used a mipmap(drawable) image to display the plus sign:</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="72" height="72" data-attachment-id="1051" data-permalink="https://www.truiton.com/2015/04/floating-action-buttons-android/ic_add/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/ic_add.png?fit=72%2C72&amp;ssl=1" data-orig-size="72,72" data-comments-opened="1" data-image-title="ic_add" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/ic_add.png?fit=72%2C72&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/ic_add.png?resize=72%2C72" alt="Android FAB add image" class="wp-image-1051"/></figure></div>



<p class="wp-block-paragraph">Next please add the following lines to detect the click events of Android floating action button:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.attachToRecyclerView(mRecyclerView);

fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //Write here anything that you wish to do on click of FAB
                
        // Code to Add an item with default animation
        int index = mAdapter.getItemCount();
        DataObject obj = new DataObject("Some Primary Text " + index,
                "Secondary " + index);
        ((MyRecyclerViewAdapter) mAdapter).addItem(obj, index);
        //Ends Here
    }
});</pre>



<p class="wp-block-paragraph">This would result in a floating action button like this:</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="500" height="805" data-attachment-id="1053" data-permalink="https://www.truiton.com/2015/04/floating-action-buttons-android/android-fab-button/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-FAB-Button.png?fit=500%2C805&amp;ssl=1" data-orig-size="500,805" data-comments-opened="1" data-image-title="Android FAB Button" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-FAB-Button.png?fit=500%2C805&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-FAB-Button.png?resize=500%2C805" alt="Android FAB Button" class="wp-image-1053" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-FAB-Button.png?w=500&amp;ssl=1 500w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-FAB-Button.png?resize=186%2C300&amp;ssl=1 186w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/04/Android-FAB-Button.png?resize=300%2C483&amp;ssl=1 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /></figure></div>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading">3) <a href="https://github.com/futuresimple/android-floating-action-button" target="_blank" rel="noopener noreferrer">android-floating-action-button</a> by <a href="https://github.com/futuresimple" target="_blank" rel="noopener noreferrer">futuresimple</a></h3>



<p class="wp-block-paragraph">This library is a fork of FloatingActionButton by <a href="https://github.com/makovkastar" target="_blank" rel="noopener noreferrer">makovkastar</a>. This library offers a <code>FloatingActionsMenu</code>, its a unique menu of floating action buttons which pop up when the main floating button is clicked. This menu of floating action buttons also offer labels, just like normal menu items. This library is also very popular among android apps. It works for Android API 14 and above, has Apache 2.0 license.</p>



<h3 class="wp-block-heading">4) <a href="https://github.com/FaizMalkani/FloatingActionButton" target="_blank" rel="noopener noreferrer">FloatingActionButton</a> by <a href="https://github.com/FaizMalkani" target="_blank" rel="noopener noreferrer">FaizMalkani</a></h3>



<p class="wp-block-paragraph">This library offers a clean and simple to use implementation of floating action buttons in Android.&nbsp;This library can be used to speed up the development pace as it does not offer any useless features. A simple floating button nothing else. It works for Android API 7 and above, has MIT license.</p>



<h3 class="wp-block-heading">5) <a href="https://github.com/shell-software/fab" target="_blank" rel="noopener noreferrer">fab</a> by <a href="https://github.com/shell-software" target="_blank" rel="noopener noreferrer">shell-software</a></h3>



<p class="wp-block-paragraph">This library is highly customizable and offers a lot of features. By using this library you can add different types of animations to the floating action button. Fab can also be used to define the shadow offset, stroke color, and stroke width of the button. Its a great library under Apache 2.0 license with support from Android API 9 and above.</p>



<h3 class="wp-block-heading">6) <a href="https://github.com/Clans/FloatingActionButton" target="_blank" rel="noopener noreferrer">FloatingActionButton</a> by <a href="https://github.com/Clans" target="_blank" rel="noopener noreferrer">Clans</a></h3>



<p class="wp-block-paragraph">This library is also highly customizable offers a great range of features like shadow colors and offsets. A great feature about this library is that it offers support for custom animations. Also this library can be used to display menu items with labels. This library requires min Android API 15 to run, and has an Apache 2.0 license.</p>



<h3 class="wp-block-heading">7) <a href="https://github.com/sephiroth74/android-floating-action-menu" target="_blank" rel="noopener noreferrer">android-floating-action-menu</a> by <a href="https://github.com/sephiroth74" target="_blank" rel="noopener noreferrer">sephiroth74</a></h3>



<p class="wp-block-paragraph">Another floating action library which is inspired from Google+ floating menu. This library offers a builder pattern to build a menu of floating action buttons of same size. This is something new because with this library you can create an animation like the one in camera app of android. This library can run on Android API 9 and above, has an Apache 2.0 license.</p>



<h3 class="wp-block-heading">8) <a href="https://github.com/oguzbilgener/CircularFloatingActionMenu" target="_blank" rel="noopener noreferrer">CircularFloatingActionMenu</a> by <a href="https://github.com/oguzbilgener" target="_blank" rel="noopener noreferrer">oguzbilgener</a></h3>



<p class="wp-block-paragraph">If you wish to go for something new, you can try this library. This library offers a new feature of circular floating action buttons. Although this sort of guideline is not described in material design, but I believe its something new and innovative. This library is under MIT license and requires Android API 15 and above.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">Although I have tried to list down all the libraries for Android floating action buttons, in case I have missed out any one, please notify me. Hope this article helped you to find the best floating action button library for your project. Connect with us on Facebook, Google+, and Twitter for more updates.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2015/04/floating-action-buttons-android/">Floating Action Buttons In Android</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2015/04/floating-action-buttons-android/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1044</post-id>	</item>
		<item>
		<title>Android RecyclerView vs ListView &#124; Comparison</title>
		<link>https://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/</link>
					<comments>https://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/#comments</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Sun, 01 Mar 2015 18:33:46 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Material Design]]></category>
		<category><![CDATA[Material Design Backward Compatibility]]></category>
		<guid isPermaLink="false">http://www.truiton.com/?p=869</guid>

					<description><![CDATA[<p>Android is an evolving platform. Recently 5.0 (Lollipop) version of Android was released, along with the official&#160;RecyclerView support v7 library. As per the official documentation RecyclerView is a major enhancement over ListView. It contains many new features like ViewHolder, ItemDecorator, LayoutManager, and SmoothScroller. But one thing that certainly gives it an edge over the ListView&#8230;&#160;<a href="https://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Android RecyclerView vs ListView &#124; Comparison</span></a></p>
<p>The post <a href="https://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/">Android RecyclerView vs ListView | Comparison</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter"><a href="https://www.flickr.com/photos/thebusybrain/2492945625" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" width="640" height="439" data-attachment-id="873" data-permalink="https://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/android-recyclerview-vs-listview-featured/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/03/Android-RecyclerView-vs-Listview-Featured.jpg?fit=640%2C439&amp;ssl=1" data-orig-size="640,439" data-comments-opened="1" data-image-title="Android RecyclerView vs Listview &amp;#8211; Featured" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/03/Android-RecyclerView-vs-Listview-Featured.jpg?fit=640%2C439&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/03/Android-RecyclerView-vs-Listview-Featured.jpg?resize=640%2C439" alt="Photo Credit: TheBusyBrain - Android RecyclerView vs Listview" class="wp-image-873" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/03/Android-RecyclerView-vs-Listview-Featured.jpg?w=640&amp;ssl=1 640w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/03/Android-RecyclerView-vs-Listview-Featured.jpg?resize=300%2C206&amp;ssl=1 300w" sizes="auto, (max-width: 640px) 100vw, 640px" /></a></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Android is an evolving platform. Recently 5.0 (Lollipop) version of Android was released, along with the official&nbsp;RecyclerView support v7 library. As per the official documentation <a title="Android RecyclerView" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html" target="_blank" rel="noopener noreferrer">RecyclerView</a> is a major enhancement over <a title="Android ListView" href="http://developer.android.com/guide/topics/ui/layout/listview.html" target="_blank" rel="noopener noreferrer">ListView</a>. It contains many new features like ViewHolder, ItemDecorator, LayoutManager, and SmoothScroller. But one thing that certainly gives it an edge over the ListView is; the ability to have animations while adding or removing an item. Here in&nbsp;Android RecyclerView vs ListView sum up I would compare the various features of RecyclerView and ListView and form an opinion why it should be used in new implementations.</p>



<p class="wp-block-paragraph">In this article I will not discuss on how to implement a RecyclerView. Although If you wish to know about the implementation of it, please refer to <a title="Android RecyclerView Tutorial" href="http://www.truiton.com/2015/02/android-recyclerview-tutorial/" target="_blank" rel="noopener noreferrer">Android RecyclerView Example</a>.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">Differences Between RecyclerView and ListView</h2>



<h3 class="wp-block-heading">1. View Holders</h3>



<p class="wp-block-paragraph">In ListView, defining view holders was a suggested approach for keeping references for views. But it was not a compulsion. Although by not doing so, ListView used show stale data. Another major drawback of not using view holders could lead to a heavy operation of finding views by ids every time. Which resulted in laggy ListViews.</p>



<p class="wp-block-paragraph">This problem is solved in RecylerView by the use of <a title="Android RecyclerView ViewHolder" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ViewHolder.html" target="_blank" rel="noopener noreferrer">RecyclerView.ViewHolder</a> class. This is one of the major differences in RecyclerView and ListView. When implementing a RecyclerView this class is used to define a ViewHolder object which is used by the adapter to bind ViewHolder with a position. Another point to be noted here, is that while implementing the adapter for RecyclerView, providing a ViewHolder is compulsory. This makes the implementation a little complex, but solves the issues faced in ListView.</p>



<h3 class="wp-block-heading">2. Layout Manager</h3>



<p class="wp-block-paragraph">When speaking of ListViews, only one type of ListView is available i.e. the vertical ListView. You cannot implement a ListView with horizontal scroll. I know there are ways to implement a horizontal scroll, but believe me it was not designed to work that way.</p>



<p class="wp-block-paragraph">But now when we look at Android RecyclerView vs ListView, we have support for horizontal collections as well. In-fact it supports multiple types of lists. To support multiple types of lists it uses RecyclerView.LayoutManager class. This is something new that ListView does not have. RecyclerView supports three types of predefined Layout Managers:</p>



<ul class="wp-block-list"><li><a href="https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html"><code>LinearLayoutManager</code></a> &#8211; This is the most commonly used layout manager in case of RecyclerView. Through this, we can create both horizontal and vertical scroll lists.</li><li><a href="https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html"><code>StaggeredGridLayoutManager</code></a> &#8211; Through this layout manager, we can create staggered lists. Just like the Pinterest screen.</li><li><a href="https://developer.android.com/reference/android/support/v7/widget/GridLayoutManager.html"><code>GridLayoutManager</code></a>&#8211; This layout manager can be used to display grids, like any picture gallery.</li></ul>



<h3 class="wp-block-heading">3. Item Animator</h3>



<p class="wp-block-paragraph">Animations in a list is a whole new dimension, which has endless possibilities. In a ListView, as such there are no special provisions through which one can animate, addition or deletion of items. Instead later on as android evolved <a title="Android ViewPropertyAnimator" href="http://developer.android.com/reference/android/view/ViewPropertyAnimator.html" target="_blank" rel="noopener noreferrer">ViewPropertyAnimator</a> was suggested by Google&#8217;s Chet Haase in this <a title="ViewPropertyAnimator" href="https://www.youtube.com/watch?v=8MIfSxgsHIs" target="_blank" rel="noopener noreferrer">video tutorial</a> for animations in ListView.</p>



<p class="wp-block-paragraph">On the other hand comparing Android RecyclerView vs ListView, it has <a title="Android RecyclerView Item Animator" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemAnimator.html" target="_blank" rel="noopener noreferrer">RecyclerView.ItemAnimator</a> class for handling animations. Through this class custom animations can be defined for item addition, deletion and move events. Also it provides a <a title="Android RecyclerView DefaultItemAnimator" href="https://developer.android.com/reference/android/support/v7/widget/DefaultItemAnimator.html" target="_blank" rel="noopener noreferrer">DefaultItemAnimator</a>, in case you don&#8217;t need any customizations.</p>



<h3 class="wp-block-heading">4. Adapter</h3>



<p class="wp-block-paragraph">ListView adapters were simple to implement. They had a main method <a href="http://developer.android.com/reference/android/widget/Adapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29">getView</a> where all the magic used to happen. Where the views were bound to a position. Also they used to have an interesting method&nbsp;<span class="sympad"><a href="http://developer.android.com/reference/android/widget/Adapter.html#registerDataSetObserver%28android.database.DataSetObserver%29">registerDataSetObserver</a></span> where one can set an observer right in the adapter. This feature is also present in RecyclerView, but <a title="Android RecyclerView.AdapterDataObserver" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.AdapterDataObserver.html" target="_blank" rel="noopener noreferrer">RecyclerView.AdapterDataObserver</a> class is used for it. But the point in favor of ListView is that it supports three default implementations of adapters:</p>



<ul class="nolist wp-block-list"><li><a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html"><code>ArrayAdapter</code></a></li><li><a href="http://developer.android.com/reference/android/widget/CursorAdapter.html"><code>CursorAdapter</code></a></li><li><a href="http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html"><code>SimpleCursorAdapter</code></a></li></ul>



<p class="wp-block-paragraph">Whereas RecyclerView adapter, has all the functionality that ListView adapters had except the built in support for DB cursors and ArrayLists. In <a title="Android RecyclerView Adapter" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html" target="_blank" rel="noopener noreferrer">RecyclerView.Adapter</a> as of now we have to make a custom implementation to supply data to the adapter. Just like a <a title="Android BaseAdapter" href="http://developer.android.com/reference/android/widget/BaseAdapter.html" target="_blank" rel="noopener noreferrer">BaseAdapter</a> does for ListViews. Although if you wish to know more about RecyclerView adapter implementation, please refer to <a title="Android RecyclerView Tutorial" href="http://www.truiton.com/2015/02/android-recyclerview-tutorial/" target="_blank" rel="noopener noreferrer">Android RecyclerView Example</a>.</p>



<h3 class="wp-block-heading">5. Notifying Change in Data</h3>



<p class="wp-block-paragraph">When working with a ListView, if the data set is changed you have to call the <code><code></code></code><a href="https://developer.android.com/reference/android/widget/ArrayAdapter.html#notifyDataSetChanged()" target="_blank" rel="noopener noreferrer">notifyDataSetChanged</a> method of the underlying adapter to refresh data. Or set the <code><code></code></code><a href="https://developer.android.com/reference/android/widget/ArrayAdapter.html#setNotifyOnChange(boolean)" target="_blank" rel="noopener noreferrer">setNotifyOnChange</a> method to true incase you wish to call the&nbsp;<code><code></code></code><a href="https://developer.android.com/reference/android/widget/ArrayAdapter.html#notifyDataSetChanged()" target="_blank" rel="noopener noreferrer">notifyDataSetChanged</a> method automatically. But in both cases the out come is very heavy on the list. Basically it refreshes the views of list.</p>



<p class="wp-block-paragraph">But on the contrary in a RecyclerView adapter, if a single item or a range of items have changed, there are methods to notify the change accordingly. Those are <code><code></code></code><a href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter#notifyItemChanged(int)" target="_blank" rel="noopener noreferrer">notifyItemChanged</a> and <code><code></code></code><a href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,%20int)" target="_blank" rel="noopener noreferrer">notifyItemRangeChanged</a> respectively and many more like:</p>



<ul class="wp-block-list"><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter#notifyItemInserted(int)" target="_blank"><code>notifyItemInsterted</code></a></li><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter#notifyItemMoved(int,%20int)" target="_blank"><code>notifyItemMoved</code></a></li><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter#notifyItemRangeInserted(int,%20int)" target="_blank"><code>notifyItemRangeInsterted</code></a></li><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter#notifyItemRangeRemoved(int,%20int)" target="_blank"><code>notifyItemRangeRemoved</code></a></li></ul>



<p class="wp-block-paragraph">And of course it has the original method to refresh the whole list i.e. <code><code></code></code><a href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#notifyDataSetChanged()" target="_blank" rel="noopener noreferrer">notifyDataSetChanged</a> which notifies the adapted the whole data set has changed.</p>



<h3 class="wp-block-heading">6. Item Decoration</h3>



<p class="wp-block-paragraph">To display custom dividers in a ListView, one could have easily added these parameters in the ListView XML:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">android:divider="@android:color/transparent"
android:dividerHeight="5dp"</pre>



<p class="wp-block-paragraph">The interesting part about Android RecyclerView is that, as of now it does not show a divider between items by default. Although the guys at Google must have left this out for customization, intentionally. But this greatly increases the effort for a developer. If you wish to add a divider between items, you may need to do a custom implementation by using <a title="Android RecyclerView.ItemDecoration" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemDecoration.html" target="_blank" rel="noopener noreferrer">RecyclerView.ItemDecoration</a> class.</p>



<p class="wp-block-paragraph">Or you can apply a hack by using this file from official samples: <a title="DividerItemDecoration.java" href="https://chromium.googlesource.com/android_tools/+/18728e9dd5dd66d4f5edf1b792e77e2b544a1cb0/sdk/extras/android/support/samples/Support7Demos/src/com/example/android/supportv7/widget/decorator/DividerItemDecoration.java" target="_blank" rel="noopener noreferrer">DividerItemDecoration.java</a></p>



<h3 class="wp-block-heading">7. OnItemTouchListener</h3>



<p class="wp-block-paragraph">Listviews used to have a simple implementation for detection of clicks, i.e. by the use of <a href="http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html">AdapterView.OnItemClickListener</a> interface.</p>



<p class="wp-block-paragraph">But on the other hand <a title="Android RecyclerView.OnItemTouchListener" href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnItemTouchListener.html" target="_blank" rel="noopener noreferrer">RecyclerView.OnItemTouchListener</a> interface is used to detect touch events in Android RecyclerView. It complicates the implementation a little, but it gives a greater control to the developer for intercepting touch events. The official documentation states, it can be useful for&nbsp;gestural manipulations as it intercepts a touch event before it is delivered to RecyclerView.</p>



<p class="wp-block-paragraph"></p>



<h3 class="wp-block-heading">Conclusion</h3>



<p class="wp-block-paragraph">I would like to conclude this <a title="Android RecyclerView vs ListView | Comparison" href="http://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/">Android RecyclerView vs ListView</a> comparison by saying RecyclerView is filled with a lot customisable functionality. It can be very useful for implementing complex lists or grids. But also its a little difficult to implement as compared to ListView as it contains multiple classes where implementation is required. Hope this helped you decide. Please connect with us through Facebook, Google+ or Twitter for more updates.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/">Android RecyclerView vs ListView | Comparison</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">869</post-id>	</item>
		<item>
		<title>Android Material Design With Backward Compatibility</title>
		<link>https://www.truiton.com/2015/02/android-material-design-backward-compatibility/</link>
					<comments>https://www.truiton.com/2015/02/android-material-design-backward-compatibility/#comments</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Sat, 21 Feb 2015 10:37:19 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Material Design Backward Compatibility]]></category>
		<guid isPermaLink="false">http://www.truiton.com/?p=839</guid>

					<description><![CDATA[<p>Earlier mid last year Google released a unified design guideline for web, smartphones, tablets and wearable devices, called Material Design. As per Google&#8217;s official design spec, material design is inspired from the concept of paper and ink. Keeping design simple and soothing, material design guidelines suggest to maintain continuity across screens. Being an Android developer,&#8230;&#160;<a href="https://www.truiton.com/2015/02/android-material-design-backward-compatibility/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Android Material Design With Backward Compatibility</span></a></p>
<p>The post <a href="https://www.truiton.com/2015/02/android-material-design-backward-compatibility/">Android Material Design With Backward Compatibility</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="640" height="427" data-attachment-id="841" data-permalink="https://www.truiton.com/2015/02/android-material-design-backward-compatibility/material-design-backward-compatibility_f/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility_f.jpg?fit=640%2C427&amp;ssl=1" data-orig-size="640,427" data-comments-opened="1" data-image-title="Material Design Backward Compatibility_f" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility_f.jpg?fit=640%2C427&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility_f.jpg?resize=640%2C427" alt="Android Material Design Backward Compatibility" class="wp-image-841" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility_f.jpg?w=640&amp;ssl=1 640w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility_f.jpg?resize=300%2C200&amp;ssl=1 300w" sizes="auto, (max-width: 640px) 100vw, 640px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Earlier mid last year Google released a unified design guideline for web, smartphones, tablets and wearable devices, called <a title="Google Material Design" href="http://www.google.com/design/spec/material-design/introduction.html" target="_blank" rel="noopener noreferrer">Material Design</a>. As per Google&#8217;s official design spec, material design is inspired from the concept of paper and ink. Keeping design simple and soothing, material design guidelines suggest to maintain continuity across screens. Being an Android developer, my perception was converting an existing app to material design could lead to huge code rework. But thankfully AppCompat v7 r21 was released recently, supporting Android Material Design Backward Compatibility.</p>



<p class="wp-block-paragraph">The question is</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>If we design an Android app with material design will it be backward compatible?</p></blockquote>



<p class="wp-block-paragraph">The answer is yes. A single app can be designed maintaining Android material design backward compatibility. This can be done in three ways. But first lets discuss what happens if you start using it directly. Just like Android Holo theme, material design theme is also available in three variants:</p>



<ul class="wp-block-list"><li><code>@android:style/Theme.Material</code></li><li><code>@android:style/Theme.Material.Light</code></li><li><code>@android:style/Theme.Material.Light.DarkActionBar</code></li></ul>



<p class="wp-block-paragraph">But if you directly include any of these themes in <code>styles.xml</code> of your project it will give you this error:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity</p></blockquote>



<p class="wp-block-paragraph">As you may have extended <code>ActionBarActivity</code> in your activity class. This class is a support class and requires an AppCompat theme. Hence we need to include material design in a backward compatible way. As I mentioned above there are three ways we can do this. First lets discuss the most important one, where support library AppCompat v7 r21 is used.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">1. Support Library</h2>



<p class="wp-block-paragraph">Whenever a new project is created in Android Studio, by default it comes with an attached&nbsp;AppCompat v7 library. Make sure that this support library is r21. <span style="text-decoration: underline;">As this new release supports backward compatibility with material design</span>. To include it in you project add the line below in your :app build.gradle file:</p>



<p class="lang:default decode:true wp-block-paragraph"><code>compile 'com.android.support:appcompat-v7:21.0.3'</code></p>



<p class="wp-block-paragraph">Using the AppCompat v7 r21 supports the <strong>maximum</strong> compatibility out of the three approaches. You can utilize the AppCompat library for displaying material theme by including code below in your regular styles.xml:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;resources>
    &lt;!-- Base application theme. -->
    &lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        &lt;!-- Main theme colors -->
        &lt;!--   your app branding color for the app bar -->
        &lt;item name="colorPrimary">#3F51B5&lt;/item>
        &lt;!--   darker variant for the status bar and contextual app bars -->
        &lt;item name="colorPrimaryDark">#303F9F&lt;/item>
        &lt;!--   theme UI controls like checkboxes and text fields -->
        &lt;item name="colorAccent">#FF4081&lt;/item>
    &lt;/style>
&lt;/resources>
</pre>



<p class="wp-block-paragraph">I have defined only three items of the material theme, but for complete Android material design backward compatibility, you can define all of them here. As of now AppCompat v7 r21 does not support all the widgets for backward compatibility, but it can support some of the major widgets:</p>



<ul class="wp-block-list"><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/widget/EditText.html" target="_blank"><code>EditText</code></a></li><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/widget/Spinner.html" target="_blank"><code>Spinner</code></a></li><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/widget/CheckBox.html" target="_blank"><code>CheckBox</code></a></li><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/widget/RadioButton.html" target="_blank"><code>RadioButton</code></a></li><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/support/v7/widget/SwitchCompat.html" target="_blank"><code>SwitchCompat</code></a></li><li><a rel="noopener noreferrer" href="https://developer.android.com/reference/android/widget/CheckedTextView.html" target="_blank"><code>CheckedTextView</code></a></li></ul>



<p class="wp-block-paragraph">I tried to customize them by applying a theme, have a look at the screen shot.</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="400" height="702" data-attachment-id="842" data-permalink="https://www.truiton.com/2015/02/android-material-design-backward-compatibility/material-design-backward-compatibility/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility.png?fit=400%2C702&amp;ssl=1" data-orig-size="400,702" data-comments-opened="1" data-image-title="Material Design Backward Compatibility" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility.png?fit=400%2C702&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility.png?resize=400%2C702" alt="Android Material Design Backward Compatibility" class="wp-image-842" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility.png?w=400&amp;ssl=1 400w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2015/02/Material-Design-Backward-Compatibility.png?resize=171%2C300&amp;ssl=1 171w" sizes="auto, (max-width: 400px) 100vw, 400px" /></figure></div>



<h2 class="wp-block-heading">2. Provide v21 layouts</h2>



<p class="wp-block-paragraph">If you are planning to display material design only on new devices then you can take this approach as well. Its fairly simple. Just define the new layouts for v21(Android Lollipop), in <code>res/layout-v21</code> folder of your project. Your app will show these layout only when an Android 5.0 device is in use.</p>



<h2 class="wp-block-heading">3. Provide v21 styles</h2>



<p class="wp-block-paragraph">Another way of supporting Android material design backward compatibility is by using material theme styles only for v21(Android Lollipop). This can be done by defining a new <code>style.xml</code> file in <code>res/values-v21/</code> folder of your project. These styles would also be displayed only in Android 5.0 devices.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">With this I would like to conclude by saying, the new material design theme released by Google, can be included in existing projects, in three possible ways. Although each way has its own pros and cons but personally I would go with the first approach. It may be most difficult one to implement, but it supports maximum backward compatibility. Hope this helped you in making an informed decision. Please connect with us through Facebook, Google+ and Twitter for more updates.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2015/02/android-material-design-backward-compatibility/">Android Material Design With Backward Compatibility</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2015/02/android-material-design-backward-compatibility/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">839</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.truiton.com @ 2026-08-04 19:29:14 by W3 Total Cache
-->