Friday 28 August 2015

Switch in Android

activity_main.xml
-------------------
<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:orientation="vertical"

    android:id="@+id/mr"

    tools:context=".MainActivity"

    android:background="#000000">



    <Switch

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Switch"

        android:id="@+id/switch1"

        android:layout_marginTop="20dp"

        android:textSize="40dp"

        android:textColor="#ffffff"

        android:background="#99cc00"

        android:layout_gravity="center_horizontal"

        android:checked="false" />

</LinearLayout>

MainActivity.Java
-------------------
package com.android.anil.switchinandroid;



import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.CompoundButton;

import android.widget.Switch;

import android.widget.Toast;



public class MainActivity extends AppCompatActivity {

     Switch s;
  @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        s=(Switch)findViewById(R.id.switch1);

        s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){

         @Override

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){

           if(buttonView.isChecked()){

              Toast.makeText(getApplicationContext(),"ON",5000).show();

            }else{

              Toast.makeText(getApplicationContext(),"OFF",5000).show();

                }

            }

        });

    }

}

Output is:
-------------
        



ToggleButton in Android

activity_main.xml
-------------------
<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:id="@+id/myid"

    android:orientation="vertical"

    tools:context=".MainActivity">





    <ToggleButton

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New ToggleButton"

        android:id="@+id/toggleButton"

        android:layout_marginTop="25dp"

        android:layout_gravity="center_horizontal" />

</LinearLayout>


MainActivity.Java
----------------------
package com.android.anil.togglebutton;



import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.CompoundButton;

import android.widget.Toast;

import android.widget.ToggleButton;



public class MainActivity extends AppCompatActivity {

   ToggleButton tb;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        tb=(ToggleButton)findViewById(R.id.toggleButton);

       tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

       @Override

       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

             if(buttonView.isChecked()){

                Toast.makeText(getApplicationContext(),"ON",5000).show();

            }else{

              Toast.makeText(getApplicationContext(),"OFF",5000).show();



                }

            }

        });



    }

}

Output is:
------------




Horizontal ScrollView in Android

Activity_main.xml
---------------------------
<HorizontalScrollView

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:id="@+id/my">

<LinearLayout

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="horizontal"

    tools:context=".MainActivity">

  <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New Button"

        android:id="@+id/button" />



    <CheckBox

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New CheckBox"

        android:id="@+id/checkBox3" />



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New Button"

        android:id="@+id/button8" />



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceMedium"

        android:text="Medium Text"

        android:id="@+id/textView2" />



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceLarge"

        android:text="Large Text"

        android:id="@+id/textView" />



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New Button"

        android:id="@+id/button6" />



    <CheckBox

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New CheckBox"

        android:id="@+id/checkBox" />



    <CheckBox

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New CheckBox"

        android:id="@+id/checkBox2" />



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New Button"

        android:id="@+id/button5" />



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New Button"

        android:id="@+id/button7" />



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New Button"

        android:id="@+id/button4" />



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New Button"

        android:id="@+id/button2" />



    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="New Button"

        android:id="@+id/button3" />

</LinearLayout>

</HorizontalScrollView>
 There No Java Code Just We need to Change the Xml or Html Code

Output is :
-------------









Vertical ScrollView in Android

Activity_main.xml
----------------------
<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="fill_parent"
   
android:layout_height="fill_parent"
   
android:id="@+id/hh">

    <
LinearLayout
       
android:layout_width="match_parent"
       
android:layout_height="match_parent"
       
android:orientation="vertical"
       
tools:context=".MainActivity">


    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button" />

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button2" />

    <
Button
       
style="?android:attr/buttonStyleSmall"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button3" />

    <
CheckBox
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New CheckBox"
       
android:id="@+id/checkBox" />

    <
RadioButton
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New RadioButton"
       
android:id="@+id/radioButton" />

    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:textAppearance="?android:attr/textAppearanceMedium"
       
android:text="Medium Text"
       
android:id="@+id/textView2" />

    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:textAppearance="?android:attr/textAppearanceSmall"
       
android:text="Small Text"
       
android:id="@+id/textView" />

    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:textAppearance="?android:attr/textAppearanceLarge"
       
android:text="Large Text"
       
android:id="@+id/textView3" />

    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:textAppearance="?android:attr/textAppearanceMedium"
       
android:text="Medium Text"
       
android:id="@+id/textView6" />

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button10" />

    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:textAppearance="?android:attr/textAppearanceMedium"
       
android:text="Medium Text"
       
android:id="@+id/textView5" />

    <
TextView
       
android:layout_width="wrap_content"
        
android:layout_height="wrap_content"
       
android:textAppearance="?android:attr/textAppearanceLarge"
       
android:text="Large Text"
       
android:id="@+id/textView4" />

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button7" />

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button8" />

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button9" />

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button4"
       
android:layout_gravity="center_horizontal" />

    <
CheckBox
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New CheckBox"
       
android:id="@+id/checkBox2" />

    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button6" />

    <
Button
       
style="?android:attr/buttonStyleSmall"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="New Button"
       
android:id="@+id/button5" />
</
LinearLayout>
</
ScrollView>


There No Java Code Just We need to Change the Xml or Html Code

Output is :
-------------







Thursday 27 August 2015

RadioButton1 in Android

activity_main.xml
----------------------
<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"
   
tools:context=".MainActivity"
   
android:orientation="vertical"
   
android:id="@+id/gddd">


    <
RadioGroup
       
android:layout_width="fill_parent"
       
android:id="@+id/radiogroup1"
       
android:layout_height="wrap_content"
       
android:layout_marginTop="25dp">
        <
RadioButton
           
android:layout_width="fill_parent"
           
android:id="@+id/radio1"
           
android:text="Android"
           
android:layout_height="wrap_content" />
        <
RadioButton
           
android:layout_width="fill_parent"
            
android:id="@+id/radio2"
           
android:text="Ios"
           
android:layout_height="wrap_content" />
        <
RadioButton
           
android:layout_width="fill_parent"
           
android:id="@+id/radio3"
           
android:text="Windows"
            
android:layout_height="wrap_content" />
        <
RadioButton
           
android:layout_width="fill_parent"
           
android:id="@+id/radio4"
           
android:text="Blackberry"
           
android:layout_height="wrap_content" />
        <
RadioButton
           
android:layout_width="fill_parent"
           
android:id="@+id/radio5"
           
android:text="Symbain"
           
android:layout_height="wrap_content" />
        <
RadioButton
           
android:layout_width="fill_parent"
            
android:id="@+id/radio6"
           
android:text="Bada"
           
android:layout_height="wrap_content" />

</
RadioGroup>
</
LinearLayout>
MainActivity.Java
-------------------
package com.android.anil.radiobutton1;



import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.Toast;



public class MainActivity extends AppCompatActivity {

    RadioGroup rg;



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);



        rg=(RadioGroup)findViewById(R.id.radiogroup1);

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override

            public void onCheckedChanged(RadioGroup group, int checkedId) {

                int id=rg.getCheckedRadioButtonId();

                RadioButton rb=(RadioButton)findViewById(id);

                String  s1=rb.getText().toString();

       Toast.makeText(getApplicationContext(),"Mobile is : "+s1,5000).show();


            }

        });

    }
}
Output is :
------------------

















Encryption Decryption Example Android Using AES Alogirthm

activity_main.xml ------------------------- <?xml version="1.0" encoding="utf-8"?> <LinearLayou...