Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button. If you have any doubt regarding create a new project Click Here.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<balaji.slidingdrawer_lr.Transparent
android:id="@+id/popup_window"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="30px">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="20dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Left to Right Sliding" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:text="Jelly Bean" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:text="Ice Cream Sandwich" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:text="HoneyComb" />
</balaji.slidingdrawer_lr.Transparent>
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle"/>
</LinearLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.slidingdrawer_lr;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
CheckBox cb1,cb2,cb3;
int key=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Transparent popup = (Transparent) findViewById(R.id.popup_window);
popup.setVisibility(View.GONE);
final Button btn=(Button)findViewById(R.id.handle);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(key==0){
key=1;
popup.setVisibility(View.VISIBLE);
// btn.setBackgroundResource(R.drawable.ic_launcher);
}
else if(key==1){
key=0;
popup.setVisibility(View.GONE);
// btn.setBackgroundResource(R.drawable.ic_action_search);
}
}
});
}
}
Step 4 : Open src -> package -> Transparent.java and add following code :
package balaji.slidingdrawer_lr;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class Transparent extends LinearLayout
{
private Paint innerPaint, borderPaint ;
public Transparent(Context context, AttributeSet as) {
super(context, as);
init();
}
public Transparent(Context context) {
super(context);
init();
}
private void init() {
innerPaint = new Paint();
innerPaint.setARGB(225, 75, 75, 255);
innerPaint.setAntiAlias(true);
borderPaint = new Paint();
borderPaint.setARGB(255, 255, 255, 255);
borderPaint.setAntiAlias(true);
borderPaint.setStyle(Style.STROKE);
borderPaint.setStrokeWidth(20);
}
public void setInnerPaint(Paint innerPaint) {
this.innerPaint = innerPaint;
}
public void setBorderPaint(Paint borderPaint) {
this.borderPaint = borderPaint;
}
@Override
protected void dispatchDraw(Canvas canvas) {
RectF drawRect = new RectF();
drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
super.dispatchDraw(canvas);
}
}
Step 5 : Open AndroidManifest.xml and add following code :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="balaji.slidingdrawer_lr"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Transparent"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
<category android:name="q.w.e.r" />
</intent-filter>
</activity>
</application>
</manifest>
Step 6 : Open res ->values ->strings.xml and add following code :
<resources>
<string name="app_name">SlidingDrawer_LR</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
Step 7 : Our output will be like this :
B. Top to Bottom Sliding Drawer Creation in Android
Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button. If you have any doubt regarding create a new project Click Here.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<balaji.slidingdrawer_tb.Transparent
android:id="@+id/popup_window"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="30px">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="20dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:text="Top to Bottom Sliding" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:text="Jelly Bean" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:text="Ice Cream Sandwich" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:text="HoneyComb" />
</balaji.slidingdrawer_tb.Transparent>
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle"/>
</LinearLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.slidingdrawer_tb;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
CheckBox cb1,cb2,cb3;
int key=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Transparent popup = (Transparent) findViewById(R.id.popup_window);
popup.setVisibility(View.GONE);
final Button btn=(Button)findViewById(R.id.handle);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(key==0){
key=1;
popup.setVisibility(View.VISIBLE);
// btn.setBackgroundResource(R.drawable.ic_launcher);
}
else if(key==1){
key=0;
popup.setVisibility(View.GONE);
// btn.setBackgroundResource(R.drawable.ic_action_search);
}
}
});
}
}
Step 4 : Open src -> package -> Transparent.java and add following code :
package balaji.slidingdrawer_tb;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class Transparent extends LinearLayout
{
private Paint innerPaint, borderPaint ;
public Transparent(Context context, AttributeSet as) {
super(context, as);
init();
}
public Transparent(Context context) {
super(context);
init();
}
private void init() {
innerPaint = new Paint();
innerPaint.setARGB(225, 75, 75, 255);
innerPaint.setAntiAlias(true);
borderPaint = new Paint();
borderPaint.setARGB(255, 255, 255, 255);
borderPaint.setAntiAlias(true);
borderPaint.setStyle(Style.STROKE);
borderPaint.setStrokeWidth(20);
}
public void setInnerPaint(Paint innerPaint) {
this.innerPaint = innerPaint;
}
public void setBorderPaint(Paint borderPaint) {
this.borderPaint = borderPaint;
}
@Override
protected void dispatchDraw(Canvas canvas) {
RectF drawRect = new RectF();
drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
super.dispatchDraw(canvas);
}
}
Step 5 : Open AndroidManifest.xml and add following code :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="balaji.slidingdrawer_tb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Transparent" ></activity>
</application>
</manifest>
Step 6 : Open res ->values ->strings.xml and add following code :
<resources>
<string name="app_name">SlidingDrawer_TB</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
Step 7 : Our output will be like this :
C. Right to Left Sliding Drawer Creation in Android
Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button. If you have any doubt regarding create a new project Click Here.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout 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" >
<SlidingDrawer
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:layout_marginTop="200dp"
android:content="@+id/content"
android:handle="@+id/handle" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#00FF00">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="42dp"
android:textSize="25dp"
android:text="Right to Left" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="Jelly Bean"
android:textSize="17dp"
/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="Ice Cream Sandwich"
android:textSize="17dp"
/>
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="HoneyComb"
android:textSize="17dp"
/>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.slidingdrawer_rl;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Step 4 : Open AndroidManifest.xml and add following code :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="balaji.slidingdrawer_rl"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step 5 : Open res ->values ->strings.xml and add following code :
<resources>
<string name="app_name">SlidingDrawer_RL</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
Step 6 : Our output will be like this :
D. Bottom to Top Sliding Drawer Creation in Android
Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button. If you have any doubt regarding create a new project Click Here.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout 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" >
<SlidingDrawer
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:layout_marginLeft="80dp"
android:layout_marginTop="150dp"
android:content="@+id/content"
android:handle="@+id/handle" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#00FF00">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="42dp"
android:textSize="25dp"
android:text="Bottom to Top" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="Jelly Bean"
android:textSize="17dp"
/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="Ice Cream Sandwich"
android:textSize="17dp"
/>
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="HoneyComb"
android:textSize="17dp"
/>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.slidingdrawer_bt;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Step 4 : Open AndroidManifest.xml and add following code :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="balaji.slidingdrawer_bt"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step 5 : Open res ->values ->strings.xml and add following code :
<resources>
<string name="app_name">SlidingDrawer_BT</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
Step 6 : Our output will be like this :
No comments:
Post a Comment