Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Wednesday, November 30, 2016

TextView


In Android, TextView is use to display text data on the screen. For the better user interference this is very important to customize the text view. In this tutorial i am covering some points of customization.
 


 
 
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />


Steps to use TextView in your project.
  1. Crate a project in android studio.
     
  2.  Open your main_activity.xml and update it-
    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        tools:context="com.pankaj.textviews.MainActivity">
    
        <!--__________________________________________________-->
        <!--                                                                                                    -->
        <!--                               create two TextView                                     -->
        <!--__________________________________________________-->
        <!--                                                                                                    -->
        <!--                             This is simple TextView                                  -->
        <!--__________________________________________________-->
        
       
     <TextView
            android:id="@+id/tvTextViewSimple"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!" />
    
        <!--__________________________________________________-->
        <!--                                                                                                    -->
        <!--                            This is Customized TextView                          -->
        <!--__________________________________________________-->
       
     <TextView
            android:id="@+id/tvTextViewCustom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:background="@color/colorPrimary"
            android:inputType="text"
            android:padding="10dp"
            android:text="Hello World!"
            android:textAllCaps="true"
            android:textColor="@android:color/white"
            android:textSize="15sp"
            android:textStyle="bold|italic" /> 
        <!--__________________________________________________-->
        <!--                                                                                                    -->
        <!--              Set dynamic text to TextView at run time                      -->
        <!--__________________________________________________-->
       
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:onClick="setTextToTextView"
        android:text="Set text to textview" />
    
     </LinearLayout>
    
    
      
  3. There are number of properties used to customize textview. Some of them are described here-


    //for providing id to the TextView
    android:id="@+id/tvTextViewCustom" 
    
    
    //for providing width to the TextView, it can be wrap_content, match_parent, fill_parent
    android:layout_width="wrap_content"
    
    
    //for providing height to the TextView, it can be wrap_content, match_parent, fill_parent
    android:layout_height="wrap_content"
    
    
    //for providing space from outside objects, this value can be in dp,px,sp,in,mm,pt etc.
    android:layout_margin="20dp"
    
    
    //for providing background to the TextView, this value can be color, drawable etc. 
    android:background="@color/colorPrimary"
    
    
    //for providing data viwing place inside the TextView, this value can be center, left, rieght, top, bottom, end, fill, center_horizontal, center_vertical etc.  
    android:gravity="center"
    
    
    //for providing input type to the TextView, this value can be text, phone, password etc.
    android:inputType="text"
    
    
    //for providing space from own borders, this value can be in dp,px,sp,in,mm,pt etc. 
    android:padding="10dp"
    
    
    
    //for providing the text data to the TextView.
    android:text="Hello World!"
    
    
    //for showing all text in caps.
    android:textAllCaps="true"
    
    
    //for changing the text color of textview.
    android:textColor="@android:color/white"
    
    
    //for changing the text size of textview, this value can be in dp,px,sp,in,mm,pt etc.
    android:textSize="15sp"
    
    
    //for changing the text style of textview, this value can be in bold,italic,normal etc.
    android:textStyle="bold|italic"
    
    
      

  4. Open your MainActivity.JAVA class and update it for change text at run time-

    package com.pankaj.textviews;
    
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.TextView;
    
    public class MainActivity extends AppCompatActivity {
    
        //Create object of text views
        TextView tvTextViewSimple, tvTextViewCustom;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            //initialize text views
            tvTextViewSimple = (TextView) findViewById(R.id.tvTextViewSimple);
            tvTextViewCustom = (TextView) findViewById(R.id.tvTextViewCustom);
        }
        
        /*__________________________________________________________*/
        /*                                                                                                                    */
        /*__Methode will be call when user click on "SET TEXT TO TEXTVIEW"__*/
        /*__________________________________________________________*/
    
        public void setTextToTextView(View view) {
    
            tvTextViewSimple.setText("Simple text updated at run time");
            tvTextViewCustom.setText("Custom text updated at run time");
        }
    }
      

  5. Now all the development process for text view has completed, Please run the application.


  6. Now click on "SET TEXT TO TEXTVIEW" and see the result on screen-
     



  7.  Good bye, Thanks to read this blog.




Tuesday, November 29, 2016

Hello World

It will be a simple program in which we will see how to output a sample text, say, Hello World in an android virtual device.


 Steps to create a hello world project on android studio.
  1. Crate a project in android studio.
  2.  Update your main_activity.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:gravity="center"
        android:layout_height="match_parent"
        tools:context="com.pankaj.helloworld.MainActivity">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!" />
    </RelativeLayout>
    
      
  3. No change in your MainActivity.JAVA

    package com.pankaj.helloworld;
    
    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);
        }
    }
    
    

     
  4. Now all the development has completed for hello world application, Please run the project.

  5. Now you will see result screen-

     
  6.  Good bye, Thanks to read this blog.




Wednesday, November 23, 2016

Advance Android


Print/Save PDF from Webview is usable when you want to save print webview content. you can see it in this tutorial.





Bar Code & QR Code Scanner is used to scan BAR & QR code scanning. you can see it in this tutorial.

Autofit Recyclerview  is used to show number of column which can be auto adjust with screen size. you can see it in this tutorial.





Send mail in background - Send mail in background is a process to send mail by without open default mail composer. By this we can send number of mail in the background. Also if an application owner wants to send mail in the background without knowing to user, then this is also usefull in this case.



Firebase Cloud Messaging (FCM) - Google has an alternative which is easier than gcm. 

 
Firebase Analytics - Firebase Analytics is a free, out-of-the-box analytics solution that inspires actionable insights based on app usage and user engagement.



Simple Webservice - A web service is a standard for exchanging information between different types of applications irrespective of language and platform. 


Image Loader - Universal Image Loader aims to provide a powerful, flexible and highly customizable instrument for image loading, caching and displaying. It provides a lot of configuration options and good control over the image loading and caching process. 


Facebook Integration - To provide the one click signup and signin process in the application, Android developers provide the login with social sites facilities like- facebook, twitter, linkedin, g+ etc. This tutorial guide you for facebook one click signup and signin process.  


RecyclerView is more advanced version of ListView with improved performance and other benefits. In this tutorial i am using creating vertical and horizontal listing with card view. 


Linkedin Integration - To provide the one click signup and signin process in the application, Android developers provide the login with social sites facilities like- facebook, twitter, linkedin, g+ etc. This tutorial guide you for Linkedin one click signup and signin process.


Place Picker is use to select single place from number of place choice on map.


Place search is used to search place by entering keyword in search field, then this provides the suggested list of place and choose any one from number of suggested place. 


NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.


Fragment in this tutorial i will cover creation of fragment, BackStack, POP From BackStack etc.


Square image view is used to show a non square image into the form of square.