Tuesday, 9 September 2014

Custom dialog box in android with Example

In this android application development tutorial i am going to demonstrate how to create custom dialog in android. Android have many features and while creating a dialog in the android we just don't want to be limited to the default theme of an android dialog.

So, In this tutorial you will learn how to create your own custom dialog in android.

How to Create Custom Dialog Box in android



Go to File -> new and  Create a New Android Application Project 

Now our new android project is ready and now as we want to create custom dialog box then we should have a layout for our Custom Dialog.


Now again Go to File -> New and select Android XML File and name it customdialog.xml

As we are going to add image in our custom android dialog box simply drag any image in drawable folder and then copy it there.

Now navigate to image and media and then simply click and drag ImageView in to the layout.



And now select your image for your custom dialog box and then simply add some message there and we are done with the designing of android custom dialogbox.


Here is the code for customdialog.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="46dp"
        android:text="Heyyy!! I am cute cat"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="26dp"
        android:src="@drawable/cat" />
</RelativeLayout>
 Now again navigate to our Activity_main.xml and then simply drag and drop one button.

Navigate to our MainActivity.java file and then simply create onclick method for the button and write the following code.

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    Button S = (Button) findViewById(R.id.button1);
    S.setOnClickListener(new OnClickListener(){
        public void onClick(View arg0) {
            Dialog CD = new Dialog(MainActivity.this);
            CD.setContentView(R.layout.customdialog);
            CD.setTitle("This is custom dialog box");
            CD.show();           
        }
    });
    }
}
Now we are done!

Now run your app and then simply click on Show my custom dialogbox button and then it will show you the custom dialogbox.



You have successfully created awesome custom dialog box in android. If you have any question about creating custom dialog box in android then feel free to ask!
Continue Reading

Friday, 29 August 2014

Android Layouts – Linear, Relative and Table Layout

Hey guys in this android tutorial we will be discussing about layouts in android. There are basically 3 layouts in android named Linear layout, Relative layout and table layout. Layouts actually define the visual structure of user interface. Android allows us to create a layout to design user interface and we can easily create a layout using xml file (We can also create a layout using java programming).

Linear Layout in android


There are two types of linear layouts 1. Horizontal Linear Layout and 2. Vertical Linear Layout.
Suppose that our default layout is Vertical Linear Layout so when you add some Form Widgets like button, text view etc. then it will be arranged in the stack fashion! though there is a space for to add other widgets but it will not allow you to add it.

Linear vertical layout

You can use the both of the layout at the same time! like your default layout is Vertical Linear layout then simply add horizontal linear layout inside it and you will be able to place the widgets side by side like this.

Linear annd horizontal layout

Here is an xml code for the same.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>
</LinearLayout>
You can also do the reverse thing too :)

Relative Layout in android

Relative layout in android is most popular and its mostly being using because it works fine in both of the views portrait and landscape. that’s why it’s mostly being used. You can also use grid and table layout to design your application well.
Continue Reading

Thursday, 28 August 2014

Android fullscreen activity

Hey guys in this android tutorial i am going to demonstrate how to create a fullscreen android activity in android. This is a quick tip android tutorial.

Creating FullScreen activity in android

Android fullscreen activity
Let’s start :)
Go to file –> New and select Android Application Project and then simply give it a name and create a new android project.
Now! open AndroidManifest.xml and then simply open its xml format.
android manifest 
Now in activity simply add the following code.
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
And make sure that your API level is 13 else it will not work! Now simply save your project and run it :)
If you have any questions then feel free to make a comment!
Continue Reading

What is activity in android

In this android application development tutorial you will learn about android activities and about its life cycle. so, lets start the tutorial :)

In android when you create a new project then you have already created one activity called main activity. Activity is nothing but the screen of your android app.

Actually activity is primary building blocks  of an android. If we talk about any other android application like WhatsApp then list of contact is another activity, when you send message to one person then its also another activity. Here is the lifecycle of an android activity.

Lifecycle of an android activity.

vlcsnap-2014-08-28-11h50m09s86
When the android app starts android system constantly calls different activities and methods. When the app starts the methods onCreate(), onStart() and onResume() is going to be are going to be called.
When your app is shutdown, the methods onPause(), onStop() and onDestroy() are going to be called and these methods are going to be needed for app crash and to minimize the system resources. 
Continue Reading

Wednesday, 27 August 2014

Get started developing android app using SDK

Hey guys this is me Siddharth Solanki, Android app developer, Web application developer, Web application security researcher and i have started this blog to share some awesome android application development tutorial and  to share some awesome tricks with you guys!

Learn android application development

Getting started with android 
Before getting started with android application development, make sure you know core java’s concepts like creating object, method overloading, method overriding, constructors, thread and all.
So, are you ready to learn android application development ? :D
Okay, then :D
And extract it in new folder and make sure you have installed JAVA SDK, because android is based on java and without java it wouldn't work.
Now extract android SDK and make sure you have set an environmental variables for android and java.
Now open eclipse and Go to File –> new and Android Application Project.  
Capture
Now write your first application name, Project Name and package name and then simply hit next.
android appliciaton development basic
Now if you don’t want to set an icon for your android app then unmark “create custom launcher icon” and then simply hit next 3 times and then hit finish.
android emmulator
Now our very first Android Hello Word app is ready! now to run this application we need android emulator. So, we have to create android virtual device.
Go to windows –> android virtual device manager and then create a new virtual device.
Now simply run your application!
Congratulations you have made your very first android app successfully!
Well this is very basic tutorial, just stay connected with us for more awesome android application development tutorials!
Continue Reading
Designed By Blogger Templates