AndroidX - Android Extension Library

Android X or Extension New Name and Packaging for the Andrioid Support Library .

What is Support Library ? 

The Android Support Library package is a set of code libraries that provide backward-compatible versions of Android framework APIs as well as features that are only available through the library APIs. Each Support Library is backward-compatible to a specific Android API level.

Read More »

Android Material Design TabLayout With Icon

TabLayout provides a horizontal layout to display tabs. The Tabs inside the TabLayout is Scroll-able and  is also used to switch between different views .The design support library simplifies the process of Creating TabLayout  widget and  adding tabs to it . In this tutorial we will see how to create tab layout with icons .




Build Gradle


Add the design support library as dependencies to the build.gradle(Module:app) file.

file : build.gradle
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
}

Color


Create a resource file in the res/values folder called colors.xml. Modify it as below:

file : colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="primary">#3F51B5</color>
    <color name="primary_dark">#303F9F</color>
    <color name="accent">#ffffff</color>
    <color name="fragment_bg">#e5e5e5</color>
</resources>

Style


Modify res/values/styles.xml as below:

file : styles.xml
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
    </style>
</resources>


XML Layout


Create a XML Layout file activity_main.xml in the res/layout . which contains Coordinate layout as parent view and isnide this add AppBarLayout and ViewPager.

  • AppBarLayout : The design library provides the AppBarLayout inside this view add Toolbar and TabLayout 
  • ViewPager :  The ViewPager will be used to enable horizontal paging between tabs.

file : activity_main.xml
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>


Fragment For Each Tab


Create a Fragment for each tab in tablayout .

file : people_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fragment_bg">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="148dp"
        android:src="@drawable/ic_action_person" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:gravity="center"
        android:text="People"
        android:textSize="30sp" />

</RelativeLayout>

Create PeopleFragment and extend this class to Fragment and inflate this fragment with above defined xml layout .

file : PeopleFragment
package com.tutorialsbuzz.tablayoutdemo.TabFragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.tutorialsbuzz.tablayoutdemo.R;

public class PeopleFragment extends Fragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
                return inflater.inflate(R.layout.people_fragment, container, false);
    }
}


Similarly Create Two More Fragment for remaining two Tabs 


FragmentStatePagerAdapter


  • Create a ViewPagerAdapter Class and extend this class to FragmentStateViewPager .
  • Override the getItem ,getCount , getPageTitle methods of FragmentStateViewPager class .
  • Have a method addFragment which takes fragment object and title, inside this method we will create a list of fragment with it's title for each of the tabs .

file : ViewPagerAdapter.java
package com.tutorialsbuzz.tablayoutdemo;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import java.util.ArrayList;
import java.util.List;

public class ViewPagerAdapter extends FragmentStatePagerAdapter {

    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }
}


MainActivity


  • Create a MainActivity class which extends Activity class 
  • Override the onCreate method inside this method set the content of this activity with above defined activity_main.xml layout .
  • Inside the setupViewPager method make a call to addFragment method on adapter object and then call setAdapter on ViewPager reference by passing the adapter object.
  • To Setting Icons for Tabs Tablayout  , get the refrence to tabs at each position and upon which call setIcon by passing the drawable resource id .

file : MainActivity.java
package com.tutorialsbuzz.tablayoutdemo;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.tutorialsbuzz.tablayoutdemo.TabFragments.PeopleFragment;
import com.tutorialsbuzz.tablayoutdemo.TabFragments.CallFragment;
import com.tutorialsbuzz.tablayoutdemo.TabFragments.GroupFragment;

public class MainActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private TabLayout tabLayout;
    private ViewPager viewPager;

    private int[] tabIcons = {
            R.drawable.ic_action_person,
            R.drawable.ic_action_group,
            R.drawable.ic_action_call
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
        actionBar.setDisplayHomeAsUpEnabled(true);


        viewPager = (ViewPager) findViewById(R.id.viewpager);
        setupViewPager(viewPager);

        tabLayout = (TabLayout) findViewById(R.id.tablayout);
        tabLayout.setupWithViewPager(viewPager);
        setupTabIcons();

    }

    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(new PeopleFragment(), "People");
        adapter.addFragment(new GroupFragment(), "Group");
        adapter.addFragment(new CallFragment(), "Calls");
        viewPager.setAdapter(adapter);
    }

    private void setupTabIcons() {
        tabLayout.getTabAt(0).setIcon(tabIcons[0]);
        tabLayout.getTabAt(1).setIcon(tabIcons[1]);
        tabLayout.getTabAt(2).setIcon(tabIcons[2]);
    }

}


Read More »

Create Personalized Textual Animated ScreenSaver

In this post i am sharing a simple and easiest way of creating an awesome  textual based animated screensaver with some awesome template , you might be thinking whether i have to install some software to do so  the answer is absolutely no .

Instead we are using an awesome online tool called reddo(https://reddodo.com/page1.php) which allows you to create personalized textual animated screensaver of your name or any text you would like to have ,it's very easy quick to do and of-course absolutely free. 

There are lots more template which you can find in the reddodo site , Here are  some of the Screen Saver template which i created .


So lets see how to do it step by step ...

1) Visit http://www.reddodo.com/

2 ) Firstly select the template which you like



3) Fill the required data in the form and then click on Refresh Preview which gives preview of your screen saver on the right side


4) There are two ways of downloading the screen saver
  • download to your desktop by right click on preview and then click save image.
  • download to your phone by entering the link provided below , and then enter the your image identifier code.
if you find this article interesting , please do share .. :)
    Read More »

    Android ScrollView Example

    Scrollview is one of important view class in android that always you to scroll the content of the layout ,when the content of the layout goes bigger than the physical device size  

    In fact the scrollview is a special kind of framelayout that contains a single child view , and the childview that is used in it is a linear layout in  vertical orientation which can be scrollable is vertical direction 

    Lets See An Example
    Project Detail
    Project Name SampleScrollView
    Package com.tutorialsbuzz.samplescrollview
    Minimum SDK API 15
    Target SDK API 26
    Theme Theme.AppCompat.Light.DarkActionBar

    1. XML Layout


      file:-activity_main.xml
    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView"
        tools:context=".MainActivity">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <include layout="@layout/sample" />
            <include layout="@layout/sample" />
            .....
      ...
      ..
    
        </LinearLayout>
    
    </ScrollView>

      file:-sample.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:layout_marginLeft="16dp"
            android:text="@string/scroll_text"
            android:textSize="28sp" />
    
        <View
            android:layout_width="wrap_content"
            android:layout_height="4dp"
            android:layout_marginTop="20dp"
            android:background="#cccccc" />
    </LinearLayout>

    2. Activity


      file:-MainActivity.java
    package com.tutorialsbuzz.samplescrollview;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    
    public class MainActivity extends AppCompatActivity {
    
       @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
        }
    }
    


    3. RUN



    Read More »

    How to setup or configure environment variable for android sdk tools inwindows

    In this post we will see about how to setup or configure android tools and platoform tools with the system environment variable in windows .

    Setting up environment variable ,make it easier to launch the Android tools and work with android commands

    Make Sure you have already installed android sdk before , if not the visit   How to installing android sdk

    After successfully installing android sdk and configuring it with eclipse , now it's time to setup environment variable for android



    lets go step by step

    Step 1
                     Click on windows -> computer ->Properties



    Step 2   
              In Properties window  click on "Advanced system settings"



    Step 3  
     now system properties dialog comes up there click on "Environment variable"



    Step 4   
    Environment variable dialog comes up there under system variables click on "New" button , on click of "new" a dialog box 
    comes up there enter the "Variable name" and "Variable value"
                
                     Variable name can be anything , in my case i have given "ANDROID_HOME"
     
    Variable value should be android sdk installed directory  path upto "android-sdk"
                     in my case the value is "C:Program Files (x86)Androidandroid-sdk"
     
    Enter the variable name and it's value in the popup dialog and then click ok



    Step 5  
    now inside system variables select the variable with name "Path" and click on "Edit" button , on click of "Edit" a dialog box comes there edit the variable value

    value for SDK tools = %ANDROID_HOME%tools;
    value for android platform tools= %ANDROID_HOME%platform-tools;

    so add the following value
    ;%ANDROID_HOME%tools;%ANDROID_HOME%platform-tools;  to the end of path variable values and click ok

     thats it your done :)



    Step 6  
    To verify the environment variable has set or not , just  open command prompt and enter the following command  "adb version"






    Read More »

    How to Reboot Android Device In Safe Mode


    On your Windows PC, you can boot into safe mode to load Windows without any third-party software. You can do the same thing on Android with Android’s safe mode. In safe mode, Android won’t load any third-party applications. Rebooting in Safe Mode allows you to troubleshoot your device – if you’re experiencing crashes, freezes, or battery life issues.


    To Demonstrate this i have used Android Powered HTC Desire X Device.

    Step 1:

    Press and hold device power button ,you will see a dialog box from the dialog box long press "Power off" option 
    Step 2:

    After Long press of "Power off " option you will get another dialog prompt to restart in safe mode click on "Restart" button to restart in safe mode.

    After Rebooting In Safe Mode you can see the following below screen with a water mark (Safe mode) at the bottom left .

    To Exit From Safe Mode Restart your device in normal mode ( Press and hold device power button and then click on restart button ) .

    Read More »

    Android StartAcitivity for result Example

    Using startActivity we can launch new Activity and pass the data to the newly launched activity and reverse of it that is getting data from launched activity we use startActivityForResult.

    When using startActivity, your application won’t receive any notification when the newly launched .
    If you use the startActivityForResult() method instead of startActivity  you can receive data from the newly launched subactivity .

    Read More »