Tuesday, 17 October 2017

Simple Splash Screen

Hello my Android Hub ...

Today I am here with you to tell you, How to make simple Splash Screen for android application ?

Do you know what is Splash Screen ????

Answer :  Splash screen is the main application screen which runs initially when you run application. This screen will run first after that you will go to next activity.

Example : Most of you are using "paytm" application, whenever you open that app, you will find there first screen with its logo and other thing. It will stay on screen till the program sets the seconds. Usually splash screen will take 3-5 second max. 


How to implement it through Android Studio ???? 

  • Create a new Android Studio Project. 
  • Take one empty black screen.
Now, In your activity.xml file, you can set picture or text or logo whatever you want, put it over there. Here I'm sharing a one snapshot of my work. 




Now, you only need to define small line of code in your activity.java file. 
Here I'm sharing that code that you should put in your project.



Saturday, 16 September 2017

Floating EditText


Guys, some of the Andro Coder wants to give the best classic and latest design to their client. Some wants to use floating edittext. It is really very attractive design for using Edittext.

So....what is Floating EditText ?
         It is a simple edittext with some modification, when user click on that edittext to type something, the entered hint goes to upward, this is floating edittext.

How you will implement this Floating EditText ?


1) add one Gradel 

      compile 'com.android.support:design:25.0.1'

2)  Go to your layout ( .xml) file and type the bellow code. 

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

<!-- put your code here -->        

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

Into put your code section, add EditText tool. Add Hint in that so you can check floating edittext is working or not ?

"Hope you Like my Blog. Is it helpful ? Then follow this blog and suggest to your Andro-Frineds  :) "

Monday, 28 August 2017

Set Rounded ImageView | Android



Guys, sometimes you need to use your imageview as Rounded.
For that you have to implement one java class filesa and use that file in your activity.xml file.

The java class files is as bellow.


RoundedImageView.java

package com.tricktechs.makemyplace.Activity;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by PanchaL on 8/27/2017.
 */

public class RoundedImageView extends ImageView {

    public RoundedImageView(Context ctx, AttributeSet attrs) {
        super(ctx, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        Drawable drawable = getDrawable();

        if (drawable == null) {
            return;
        }

        if (getWidth() == 0 || getHeight() == 0) {
            return;
        }
        Bitmap b = ((BitmapDrawable) drawable).getBitmap();
        Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);

        int w = getWidth(), h = getHeight();

        Bitmap roundBitmap = getRoundedCroppedBitmap(bitmap, w);
        canvas.drawBitmap(roundBitmap, 0, 0, null);

    }

    public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
        Bitmap finalBitmap;
        if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
            finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
                    false);
        else
            finalBitmap = bitmap;
        Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
                finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
                finalBitmap.getHeight());

        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        paint.setDither(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(Color.parseColor("#BAB399"));
        canvas.drawCircle(finalBitmap.getWidth() / 2 + 0.7f,
                finalBitmap.getHeight() / 2 + 0.7f,
                finalBitmap.getWidth() / 2 + 0.1f, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(finalBitmap, rect, rect, paint);

        return output;
    }
}



Know, How to implement this java file in your xml file. 
Just see this bellow code. 


<com.tricktechs.makemyplace.Activity.RoundedImageView
            android:id="@+id/iv_pic"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@mipmap/user_profile_icon" />

Sunday, 13 August 2017

ListView || Simple ListView || Static ListView

ListView :

It is one of the very useful tool for Android Application.

What is ListView :

  • Fetching data from database and display it on activity using custom designed view.
  • Same view which is repeating, for that we can use ListView.
How to create ListView in Android:
  • First you need one main activity. There you should define <ListView /> tag in .xml file
  • Then only MainActivity.java is need to be coded. 
 Example 
  • Show all days using ListView 
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/activity_main"     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.tricktechs.listview.MainActivity"> 

    <ListView         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/lv_lst" >
    </ListView>

</RelativeLayout>

MainActivity.java

package com.tricktechs.listview;

import android.content.ContentResolver;
import android.database.CharArrayBuffer;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.net.Uri;
import android.support.annotation.StringRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.ArraySet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {



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

        String[] name = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
        ListView ls = (ListView) findViewById(R.id.lv_lst);
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, name);
        ls.setAdapter(adapter);



    }


}