ActivityToggleButton.java
- Code:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;
public class ActivityToggleButton extends Activity {
private ToggleButton toggleButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toggle_button);
toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(arg1){
Intent intent = new Intent(ActivityToggleButton.this,ActivityToggleButton2.class);
startActivity(intent);
overridePendingTransition(R.anim.animation_down_enter, R.anim.animation_down_exit);
}
else{
}
}
});
}
}
- Spoiler:
- import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ActivityToggleButton2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toggle_button2);
Button btnBack = (Button) findViewById(R.id.btnBackActivityToggle);
btnBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(ActivityToggleButton2.this,ActivityToggleButton.class);
startActivity(intent);
overridePendingTransition(R.anim.animation_left_enter, R.anim.animation_left_exit);
}
});
}
}
- Code:
<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="horizontal"
tools:context=".ActivityToggleButton" >
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@null"
android:button="@null"
android:textOn="@null"
android:textOff="@null"
android:background="@drawable/btntoggle" />
</LinearLayout>
- Spoiler:
- <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"
android:gravity="center"
tools:context=".ActivitySwitch2" >
<Button
android:id="@+id/btnBackActivityToggle"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Back" />
</RelativeLayout>
- Code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromYDelta="-100%p"
android:toYDelta="0%p"
android:duration="500"/>
</set>