--ADVERTISEMENT--

Google announced Material Design Support Library for Android Developers with the release of new OS, Android Lollipop 5.0 (API 21). This library includes navigation drawer view, floating action buttonsnackbarfloating labels in EditText, tabs and motion and scroll framework. These tools help us to make our android application good looking with simple step and you can easily use these tools with the help of Android Design Support Library.

Android Navigation Drawer View: Material Design Support Library

Android Navigation View Material Design Support Library

 

Android Navigation View

Making navigation drawer is very difficult and time consuming before Google announced this material design support library. With this library, you can make your navigation drawer in simple step and less time.

Related:
Android Material Design with Design Support Library
Navigation Drawer View User Interface (UI) Design for Android
Best Android Navigation Drawer Libraries Collection
Android Menus: Best Practice and Awesome Android Menu Libraries

Here I will show you how to make a Navigation Drawer with the help of android Design Support Library. Let’s start step by step.

Create a Project


Create a new project with following information.
Application name: Navigation View
Company Domain: viralandroid.com
Package name: com.viralandroid.navigationview
Minimum SDK: Android 2.2 (API 8 Froyo)


Add Design Support Library Dependency


You have to add design support library dependency to your build.gradle file to make navigation drawer view.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
}
Now, to add a navigation view in your activity layout, you have to setup your application theme from styles.xml file and your styles.xml file looks like this:
res/values/styles.xml

And add PrimaryColor and PrimaryDarkColor to your colors.xml file and it looks like this:
res/values/colors.xml


<resources>
    <color name="PrimaryColor">#ff1b6bae</color>
    <color name="PrimaryDarkColor">#ff134a88</color>
</resources>

Create Navigation Header View and Navigation Menu


res/layout/navigation_header.xml

res/menu/navigation_view_items.xml

You can add more menu items according to your wish and also can design your custom menu. Here I have created simple navigation view with a header view and menu item.


Add Navigation View to your Activity Layout


After adding navigation view design support library to your activity layout, it looks like this:
res/layout/activity_main.xml

And do not forget to update your strings.xml file.
res/values/strings.xml

<resources>
    <string name="app_name">Navigation View</string>

    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="navigation_view_item_1">Navigation Item 1</string>
    <string name="navigation_view_item_2">Navigation Item 2</string>
    <string name="navigation_view_item_3">Navigation Item 3</string>
    <string name="navigation_view_item_4">Navigation Item 4</string>
    <string name="navigation_view_item_5">Navigation Item 5</string>
    <string name="navigation_view_item_6">Navigation Item 6</string>
    <string name="navigation_view_category_1">Navigation View Category</string>
    <string name="navigation_view_category_2">Navigation View Category</string>
</resources>

Modify Your Activity File

Finally, you have to add java code to your Activity file to make navigation drawer working. Your MainActivity.java file should look like this:
src/MainActivity.java

This is how you can make your Navigation Drawer View. Then, run your application and see how it looks.

In this tutorial, I am going to show how to use android CheckBox in android application. CheckBox is a two state button that user can select or unselect. Users can check one or more option from a set. Following is the simple steps to show and control CheckBox.

Related:
Android Radio Button Example
Android SeekBar Example
Android WebView Tutorial with Example

Android Example: How to use Android CheckBox


Create a new Android Project


Let’s start by creating a new android project with following information to use android CheckBox

Application Name: Android CheckBox Example
Company Domain: viralandroid.com
Package Name: com.viralandroid.androidcheckboxexample
Minimum SDK: Android 2.2 (API 8 Froyo)

XML Layout File


Following is the xml layout file with many CheckBox and added onClick attribute in all CheckBox.
res/layout/activity_main.xml

Java Activity File


In java activity file we control the CheckBox select and the code looks like this.
src/MainActivity.java

Default content of strings.xml file
res/values/strings.xml

Now, run your application which looks like below.

Output:

Android CheckBox Example

In this tutorial, I will show how to use ToggleButton in android application. Generally, ToggleButton is used in the setting of android application like WiFi, Bluetooth, Data Connection, Sound On/Off, Alram On/Off, etc. You can find lots of attributes and classes of ToggleButton in android developer site.

Related:
Android Switch Button Example
Android CheckBox Example
Android Time Picker Example

Android Example: How to use ToggleButton in Android App


XML Layout File

res/layout/toggle_button.xml

Java Activity File

src/MainActivity.java

Strings.xml File

res/values/strings.xml

Now, run your application which will look like output given below.

Output:

Android ToggleButton Example
ToggleButton

In this tutorial, I will show how to use android radio buttons in android application. A RadioGroup is used for a set of radio buttons and radio buttons allow the users to select one option among many options. Normally, both RadioGroup and radio buttons are used together in android.

Related:
Android Layouts Tutorial
Android ListView Example
How to Implement Ripple Effect in Android

Android Example: How to use Android Radio Button


Create a new Android Project
Let’s start by creating a new android project with following information to use android radio buttons.

Application Name: Android Radio Button Example
Company Domain: viralandroid.com
Package Name: com.viralandroid.androidradiobuttonexample
Minimum SDK: Android 2.2 (API 8 Froyo)

XML Layout File

Following is the xml layout file with RadioGroup and RadioButton.
res/layout/activity_main.xml

Java Activity File

In java activity file we control the radio button by onClick event. Here, I have placed a message in toast that displays when you select one option from the set.
src/MainActivity.java

Default content of strings.xml file
res/values/strings.xml

Finally, you have finished all. Now, run your application and choose one option.

Output:

Android Radio Button Example

In this tutorial, I am going to show how to use spinner in android application to select an item from a drop down list. You can add drop down items either from java code or xml. Let’s create a new android project and try the following spinner example.

Related:
Android SeekBar Example
Android Radio Button Example
Android ListView Example

Android Example: How to use Spinner in Android


XML Layout File

res/layout/activity_main.xml

Java Activity File

src/MainActivity.java

Strings.xml File

res/values/strings.xml

Now, run your application which will look like output given below.

Output:

Android Spinner Example
Android Spinner

In this post, I am going to share a simple tip: How to launch any other android application from your app programmatically using their package name. If you don’t have any idea to find package name of android application see how to find package name of android application from PlayStore and from android app manifest file.

Launching any other installed android app from your application is very easy, you just have to use little bit java code. There are many ways to launch other installed android app from your app but here you will learn one of the simplest ways.

In this example project I have added different buttons in XML layout file to launch different applications from your app like google chrome, youtube, facebook, twitter. To test either this is working or not you must have installed these applications on your testing device or emulator. While touching Click to Launch Google Chrome, chrome browser will be opened.

Related:
How to Get Current GPS Location Programmatically in Android
Android Studio is Slow: How to Make Android Studio Fast
How to Pick an Image From SD Card Gallery and Display in Android App

Example: Launch any Installed Application From Your Android App Programmatically


Following is the content of XML layout file and java activity file.


XML Layout File

Just add four buttons and give different onClick attribute name like below
res/layout/ launch_other_application_android.xml


Java Activity File

Following is the complete content of activity file.
src/LaunchOtherApplication.java

Strings.xml File

Default content of strings.xml file
res/values/strings.xml

Example: Launch any Installed Application From Your Android App Programmatically

That’s all. Now, run your Launch Other App From Your App and click different buttons to test. Make sure that you have installed these applications in your testing device or emulator.

In this tutorial, you will learn to implement drop down list in android application and control when the user selects one of the item from a set. To make drop down, I have used Spinner. You can add drop down items either from java code or xml string array.

Related:
Android Time Picker Example
Android Layouts Tutorial
Android Material Design with Design Support Library

Android Tutorial: Android Drop Down List Example


XML Layout File

Following is the xml layout file which contains two .
res/layout/activity_main.xml

Java Activity File

Following is the java activity file which control drop down list item is selected.
src/MainActivity.java

Strings.xml File

res/values/strings.xml

Now, run your application which will look like output given below.

Output:


Android Drop Down List Example
DropDown List

Powered by Blogger.