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

Wednesday, 12 October 2016

Switch

activitymain.xml :-

<?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:orientation="vertical"
  tools:context="com.kiranapp.MainActivity"
  android:background="#ddd6d6">
<Switch
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Bluetooh"
  android:layout_marginTop="30dp"
  android:id="@+id/switch1"
  android:checked="false"
  android:layout_gravity="center_horizontal" />
</LinearLayout>

MainActivity.java
:-


package com.kiranapp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
  Switch aSwitch;


@Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   aSwitch=(Switch) findViewById(R.id.switch1);
  aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
   if (isChecked){
   Toast.makeText(MainActivity.this,"TurnOn",Toast.LENGTH_SHORT).show();
    }
  else {
 Toast.makeText(MainActivity.this,"TurnOff",Toast.LENGTH_SHORT).show();
 }
 }
});
}
}

Output :- 


Switch
Switch fig:1




Switch
Switch fig:2

Monday, 3 October 2016

Android Layouts

There are different android layouts below listed

1) FrameLayout :-
     It is designed  to a block out area on the screen to display single item.

2) LinearLayout :-
    It is a view that aligns all children in a single direction i.e vertically or horizontally.

3) RelativeLayout :-
     A Layout where the positions of the children can be described in relation to each other or to be    
     parent.

4) TableLayout :-
     It is a view  group that displays child views in relative postions.

5) ListView :-
     It is a View group that displays a list of scrollable items.

6) GridLayout :-
    A Layout that places its children in a rectangular grid.