--ADVERTISEMENT--

In this tutorial, I will show you to use android TableLayout to arrange and display different child view in rows and columns. To add different child view in rows and columns, we have to use TableRow inside TableLayout. TableLayout is a ViewGroup that displays different child views like TextView, ImageView, EditText, Button, etc in rows and columns. In this tutorial, I have used textview to arrange position but you can use any other views according to your wish.

Related:
Android Linear Layout
Android Relative Layout Example
Android Frame Layout Example
Android Navigation View - Sliding Menu with WebView

Android Table Layout Example


Following is the android table layout example code of xml layout file.
res/layout/table_layout.xml

Following default code of java activity file.
src/MainActivity.java

String resource of strings.xml file.
res/values/string.xml

Output:



Android Table Layout Example
Android TableLayout Example

Absolute layout is less flexible and harder to maintain than linear layout, relative layout, table layout, etc. To specify views inside absolute layout, you have to use android:layout_x for x-coordinate and android:layout_y for y-coordinate. In this tutorial, I will show how to use absolute layout in your android application.

Related:
Android Linear Layout
Android Relative Layout Example
Android Frame Layout Example
Android WebView Tutorial with Example

Android Absolute Layout Example


Add following xml code in your layout file.
res/layout/absolute_layout.xml

Default code of java activity file looks like this.
src/MainActivity.java

And finally, following is the strings of strings.xml file.
res/values/strings.xml

Output:


Android Absolute layout Example
Android Absolute layout

Android WebView is a View that allows you to display website, static HTML data, and your custom web page. Using WebView you can able to convert your web page into android application. Here I describe how to load HTML Data on android WebView.


Android Example: Load HTML Data/String on Android WebView App


Creating Android Project

Let’s start by creating a new android project to Load HTML Data on Android WebView with following information:
Application name: Load HTML Data on Android WebView
Company Domain: sirseni.com
Package name: com.sirseni.loadhtmldataonandroidwebview
Minimum SDK: Android 2.2 (API 8 Froyo)

Adding a WebView in Your Layout File

To load HTML string on your android WebView, first you have to add <WebView> element in your layout file.
res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/myWebView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>


Modify Your Java File

To load HTML data in your android WebView just call loadData(), here is final code of MainActivity.java file.
src/MainActivity.java

/*
* Load HTML Data on Android WebView
*
*/

package com.sirseni.loadhtmldataonandroidwebview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends Activity {

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

        WebView mWebView = (WebView) findViewById(R.id.myWebView);
        String myHtmlString = "<html><body>" +
                "<h2>This is a HTML Heading in Android WebView.</h2>\n" +
                "<p>This is a HTML paragraph in android WebView.</p>\n" +
                "\n" +
                "<h4>Following is HTML Table in WebView</h4>\n" +
                "<table border=\"1\" width=\"100%\">\n" +
                "  <tr>\n" +
                "    <td>Android</td>\n" +
                "    <td>WebView</td>\t\t\n" +
                "    <td>100</td>\n" +
                "  </tr>\n" +
                "  <tr>\n" +
                "    <td>Android</td>\n" +
                "    <td>WebView</td>\t\t\n" +
                "    <td>200</td>\n" +
                "  </tr>\n" +
                "  <tr>\n" +
                "    <td>Android</td>\n" +
                "    <td>WebView</td>\t\t\n" +
                "    <td>300</td>\n" +
                "  </tr>\n" +
                "</table>" +
                "</body></html>";
        mWebView.loadData(myHtmlString, "text/html", null);
    }
}


That’s it, now run your Load HTML Data on Android WebView application, your app is look like below screenshot.

Simple Android WebView Example and Tutorial

Implementing Navigation Back Feature to Android WebView Application

Download complete Load HTML Data/String on Android WebView Application example project source code from GitHub.


Application Screenshot:


Android Example: Load HTML Data/String on Android WebView App

In this example, I will show how to get (display) current time in android application programmatically. To get current time in android application, we use Calendar class Calendar calendar = Calendar.getInstance();.

Related:
Get Current Date in Android Programmatically
Android Material Design with Design Support Library
Check Internet Connection in Android

Android Example: How to Get (Display) Current Time in Android Programmatically


XML Layout File
res/layout/activity_main.xml

Java Activity File
src/MainActivity.java

Now, run your application and click the Get Current Time button.

Output:

Get Current Time in Android Programmatically
Get Current Time in Android

Android TextView is one of the powerful and popular UI components which is used to display texts in android application. TextView also allows us to display HTML string. So in this tutorial, you will learn to display html string inside android text view and make text of different style like heading, paragraph, lists, text style, text size, text color etc.

Displaying HTML text in android TextView is very easy. There are many ways to show html string in android textview and in this example, I will show one of the best and easy ways to display HTML string in android app.

Following example shows how to display HTML date string in android using TextView component.

Related:
How to Make Multiple Styles Inside Android TextView
How to Make Android TextView Text Selectable
Create Scrolling Text (Marquee) in Android TextView


Android Example: How to Display/Show HTML String in Android TextView


Following are the code of java file and xml layout file.

XML Layout File

res/layout/ display_html_string_in_textview.xml

Java Activity File


src/ DisplayHtmlStringAndroidTextView.java

Strings.xml File


res/values/strings.xml

 Android Example: How to Display/Show HTML String in Android TextView

Now, run your How to Display/Show HTML String in Android TextView application, you will see HTML paragraph, Headline H1, H3, list item, etc.

By default, android SDK allows us to use a set of fonts like sans, serif, mono space etc in android application using typeface attribute or property. Only default fonts may not be sufficient for your application. In this tutorial, you will learn to load custom/external fonts in your android app programmatically.

Using custom fonts in android application is very easy. You just need to add extra two line of code. But you need to download the required fonts from the internet and add it inside assets folder of your android app.

Here I have used custom font in android TextView. Like this you can use anywhere you need instead of normal font.

Related:
How to Use Font Awesome Icons in Android Application
How to Make Android TextView Text Selectable
How to Add a Library Project to Android Studio


Android Example: Loading External/Custom Fonts in Android App


Following is the step by step guide to use custom fonts in android application programmatically.

1. Create a new Android Project


Let’s start by creating a new project with following information.

Application name: Using Custom Font in Android
Company Domain: viralandroid.com
Package name: com.viralandroid.usingcustomfontinandroid
Minimum SDK: Android 2.2 (API 8 Froyo)

2. Adding Custom Fonts in Assets Folder


Create an assets fonder in your app’s main directory then copy and paste all .ttf font files which you are going to used inside assets folder.

How to Use Custom Fonts in Android Application

3. Modify XML Layout File


Open your XML layout file i.e. activity_main.xml and add a simple TextView which will look like this.

res/layout/activity_main.xml


4. Modify Java Activity File


Now open your java activities file i.e. MainActivity.java and add following code.

src/MainActivity.java

Following is the default content of strings.xml file.

res/values/strings.xml

Android Example: Loading External/Custom Fonts in Android App

That’s all. Now run your How to Use Custom Fonts in Android application.

Android ProgressBar is one of the common user interfaces (UI) component. Progress bar is used to show progress of any task to the users like in downloading, uploading, loading etc. In this tutorial, I am going to show how to create a progress bar in android application to tell user that some task is running, how much task has already been finished and how much task is left or how much time is required to finish the task.

In this simple android application I have used android.widget.ProgressBar class to create and show progress of any task.

There are many ways to show progress in android application and here you will learn one of the simplest ways to show progress/running task to the user using ProgressBar.

Related:
Android Spinner Example
Dialog Libraries for Android Project
Android User Interface (UI) Design Tutorial

Android Example: How to Create and Show Progress Bar in Android


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

XML Layout File


In this XML layout file, I have added a ProgressBar and a TextView. Progress bar is used to show a task in progress and TextView is used to show how much task has been finished and how much task is left. Following is the complete content of XML layout file.

res/layout/android_progress_bar_example.xml

Java Activity File


Following is the complete code of java activity file.

src/ProgressBarExample.java

Strings.xml File


res/values/strings.xml

Android Example: How to Create and Show Progress Bar in Android

Now run your Android Progress Bar Example application, you will see the progress bar and number count with the interval of one up to 100. When there is 100/100 the progress is completed.
Powered by Blogger.