activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <SlidingDrawer android:id="@+id/slidingDrawer1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:content="@+id/content" android:handle="@+id/handle" android:topOffset="50dip" > <Button android:id="@+id/handle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/menuname" > </Button> <LinearLayout android:id="@+id/content" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FF444444" android:gravity="center" android:orientation="vertical" > <Button android:id="@+id/item1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/item1" > </Button> <Button android:id="@+id/item2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/item2"> </Button> <Button android:id="@+id/item3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/item3" > </Button> <Button android:id="@+id/item4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/item4" > </Button> <Button android:id="@+id/item5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/item5" > </Button> </LinearLayout> </SlidingDrawer> </LinearLayout>
MainActivity.java
package in.blogspot.kantapp.slidedrawerinandroid; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button i1 = (Button)findViewById(R.id.item1); i1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_SHORT).show(); } }); } }
string.xml
<resources> <string name="app_name">SlideDrawer in Android</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="menuname">Menu</string> <string name="item1">option1</string> <string name="item2">option2</string> <string name="item3">option3</string> <string name="item4">option4</string> <string name="item5">option5</string> </resources>
No comments:
Post a Comment